首页 文章

/ admin /中的Django ImportError

提问于
浏览
2

当我尝试访问我的Django管理站点时,我收到以下错误:

/ admin /上的ImportError没有名为django.views的模块请求方法:GET请求URL:http://127.0.0.1:8000 / admin / Django版本:1.4.1异常类型:ImportError异常值:没有名为django.views的模块异常位置:/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py in import_module,第35行Python可执行文件:/ usr / bin / python Python版本:2.7.3

这是我的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('',
    url(r'^$', include('home.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)),
)

当我对 url(r'^$', include('home.urls')) 行进行评论时,管理网站会起作用 .

我无法弄清楚我的问题是什么 . 你能帮助我吗?

2 回答

  • 1

    我不确定它是否能解决你对正确答案的渴望..我尝试复制这个问题并发现不是使用

    include('home.urls')
    

    如果你用类似的东西替换它

    (admin.site.urls)
    

    或者你也可以使用

    url(r'^{{project_name}}', '{{project_name}}.{{app_name}}.views.{{some html template file}}'),
    

    然后它运作正常 . 希望它至少可以帮助你缩小影响点 .

  • 0

    您在代码中的其他位置的某个视图中出错,它正在尝试导入 django.views . 管理站点需要导入所有视图才能正确反转URL,因此即使它不在管理代码本身中也会触发错误 .

相关问题