python - Django - ImportError 在/博客。没有名为 urls 的模块

标签 python django

我是 django 的新手,正在学习中。在做一些教程练习时,我遇到了一些需要帮助的错误。

错误:/blog 上的 ImportError。没有名为 urls 的模块

名为'blog'的app下的urls.py文件是

from django.conf.urls.defaults import patterns, include, url
from mysite.blog.views import archive

urlpatterns = patterns('',
    url(r'^$',archive),
                       )

名为'blog'的应用程序下的views.py文件是

# Create your views here.
from django.template import loader, Context
from django.http import HttpResponse
from mysite.blog.models import Blogpost

def archive(request):
    posts = BlogPost.objects.all()
    t = loader.get_template("archive.html")
    c = context({'posts': posts })
    return HttpResponse(t.render(c))

mysite项目下的urls.py文件是

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
url(r'^blog/', include('mysite.blog.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)

回溯:

File "D:\Super Developer\Python\lib\site-packages\django\core\handlers\base.py" in get_response
  89.                     response = middleware_method(request)
File "D:\Super Developer\Python\lib\site-packages\django\middleware\common.py" in process_request
  67.             if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "D:\Super Developer\Python\lib\site-packages\django\core\urlresolvers.py" in is_valid_path
  531.         resolve(path, urlconf)
File "D:\Super Developer\Python\lib\site-packages\django\core\urlresolvers.py" in resolve
  420.     return get_resolver(urlconf).resolve(path)
File "D:\Super Developer\Python\lib\site-packages\django\core\urlresolvers.py" in resolve
  298.             for pattern in self.url_patterns:
File "D:\Super Developer\Python\lib\site-packages\django\core\urlresolvers.py" in url_patterns
  328.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "D:\Super Developer\Python\lib\site-packages\django\core\urlresolvers.py" in urlconf_module
  323.             self._urlconf_module = import_module(self.urlconf_name)
File "D:\Super Developer\Python\lib\site-packages\django\utils\importlib.py" in import_module
  35.     __import__(name)

Exception Type: ImportError at /blog
Exception Value: No module named urls

项目/应用的结构:

  1. 我的网站
    • 管理.py
    • 初始化.py
    • 设置.py
    • urls.py
    • wsgi.py
    • 博客
      • 初始化.py
      • 模型.py
      • views.py
      • urls.py
      • 测试.py
      • 模板 - archive.html

Python路径

['D:\Super Developer\Proj\mysite', 'C:\Windows\system32\python27.zip', 'D:\Super Developer\Python\DLLs', 'D:\Super Developer\Python\lib', 'D:\Super Developer\Python\lib\plat-win', 'D:\Super Developer\Python\lib\lib-tk', 'D:\Super Developer\Python', 'D:\Super Developer\Python\lib\site-packages']

最佳答案

url(r'^blog/', include('mysite.blog.urls')),

这可能需要改成

url(r'^blog/', include('blog.urls')),

注意:没有'mysite'前缀。

关于python - Django - ImportError 在/博客。没有名为 urls 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11185185/

相关文章:

python - 如何通过 Python 将存储在文本文件中的数据加载到 PostgreSQL 数据库中

django - 从 django 返回一个用 UTF-8 编码的 csv 和 BOM

django - Django Rest Framework 中的序列化和反序列化

python - 具有线性内核的 sklearn svc 提供奇怪的支持向量

python - Openoffice3.1 pyuno混淆错误

python - IO 错误 [Errno 2]

python - 从时间序列中插值单个值

HTML 在 Django 中无法正确呈现

python - Django 模板上下文错误

django - 将 Django auth UserAdmin 用于自定义用户模型