我是django的一个完整的菜鸟,我似乎无法启动并运行管理页面。我正确设置了urls.py,并且我在settings.py模块中启用了应用程序...所有数据库设置都已正确定义。 请帮忙 抛出的错误如下所示
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin
Django Version: 1.3
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
' jango.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
89. response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in process_request
67. if (not _is_valid_path(request.path_info, urlconf) and
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in _is_valid_path
154. urlresolvers.resolve(path, urlconf)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
342. return get_resolver(urlconf).resolve(path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
250. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
279. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
274. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/mjanja/workspace/DjangoProjectsLinux/ModelsDemo/../ModelsDemo/urls.py" in <module>
16. url(r'^admin/', include(admin.site.urls)),
Exception Type: NameError at /admin
Exception Value: name 'admin' is not defined
答案 0 :(得分:4)
你很可能错过以下几行@ urls.py的开头:
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
答案 1 :(得分:1)
似乎您可能忘记在项目根目录中的默认urls.py中取消注释几行。
检查项目根目录中的urls.py
,它至少应该具有以下内容:
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
)
另外,我在上面的settings.py中看到“django”缺少“d”:
' jango.contrib.sessions.middleware.SessionMiddleware'
答案 2 :(得分:0)
这已经很老了,但我注意到在已安装的中间件列表中,有一行缺少'django'中的'd'
Installed Middleware:
('django.middleware.common.CommonMiddleware',
' jango.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',