我是Django的新手,我正在按照激活管理网站的教程进行操作。我从教程中做了以下配置:
首先,我在settings.py的apps部分取消注释了行django.contrib.admin
。
然后我在终端中执行了python manage.py syncdb
命令。
然后我在urls.py中取消注释了行from django.contrib import admin
,admin.autodiscover()
和url(r'^admin/', include(admin.site.urls))
;结果代码是:
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'^mysite/', include('mysite.foo.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)),
)
当我运行项目时,我收到以下错误:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, , didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
我该怎么办?
感谢您的回答,但是当我尝试访问http://127.0.0.1:8000/admin
时,我收到以下错误:
DoesNotExist at /admin/
Site matching query does not exist. Lookup parameters were {'pk': 1}
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.5
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist. Lookup parameters were {'pk': 1}
Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/models/query.py in get, line 401
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/home/eren/mysite',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
Server time: Fri, 24 May 2013 23:29:03 +0300
答案 0 :(得分:2)
您应该访问http://127.0.0.1:8000/admin
而不是http://127.0.0.1:8000/
的管理网站。
注意:admin
后缀。