Skip to main content
 首页 » 编程设计

python之Django ImportError 在/admin/

2025年05月04日27artech

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

ImportError at /admin/

No module named django.views

Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Django Version: 1.4.1 Exception Type: ImportError Exception Value:

No module named 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

这是我的 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')) 行时,管理站点再次运行。

我不知道我的问题是什么。你能帮帮我吗?

请您参考如下方法:

您自己的 View 之一在代码的其他地方有一个错误,它正在尝试导入 django.views。管理站点需要导入所有 View 才能正确反转 URL,因此即使它不在管理代码本身中也会触发错误。