简体   繁体   English

Django ImportError位于/ admin /

[英]Django ImportError at /admin/

When I try to access to my Django admin site I got the following error: 当我尝试访问我的Django管理站点时,出现以下错误:

ImportError at /admin/ 在/ admin /的ImportError

No module named django.views 没有名为django.views的模块

Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Django Version: 1.4.1 Exception Type: ImportError Exception Value: 请求方法:GET请求URL: http://127.0.0.1:8000/admin/ : http://127.0.0.1:8000/admin/ :8000/admin/ Django版本:1.4.1异常类型:ImportError异常值:

No module named django.views 没有名为django.views的模块

Exception Location: /usr/local/lib/python2.7/dist-packages/django/utils/importlib.py in import_module, line 35 Python Executable: /usr/bin/python Python Version: 2.7.3 异常位置:import_module中的/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py,第35行Python可执行文件:/ usr / bin / python Python版本:2.7.3

Here is my urls.py file: 这是我的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)),
)

When I comment the line url(r'^$', include('home.urls')) , the admin site works againg. 当我评论url(r'^$', include('home.urls')) ,管理站点再次起作用。

I can't figure out what my problem is. 我不知道我的问题是什么。 Can you help me? 你能帮助我吗?

You have an error in one of your own views somewhere else in the code, which is trying to import django.views . 您尝试在django.views中导入代码的其他地方的视图中出错。 The admin site needs to import all views in order to reverse URLs properly, so is triggering the error even though it isn't in the admin code itself. 管理站点需要导入所有视图才能正确反向URL,因此即使该错误不在管理代码本身中,也会触发该错误。

I m not sure if it quenches ya thirst for the right answer.. I tried replicating the issue and found that instead of using 我不确定是否可以消除对正确答案的渴望。我尝试复制问题,发现不是使用

include('home.urls')

if you replace it with something like 如果您将其替换为类似

(admin.site.urls)

or you could also use 或者你也可以使用

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

then it works fine.Hope it at least helps you narrow down on point of impact. 希望它至少可以帮助您缩小影响范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM