我熟悉Django。
我已经成功安装并测试了一个演示站点。我现在想要打开管理模块,看看会发生什么。
我采取的步骤(授予,一些是不必要的,但我只是想确保我从一个干净的石板开始):
这是我的mysite / settings.py文件的样子(仅限相关部分)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# The next lines are my models
'mysite.foo',
'mysite.foobar',
)
这是我的mysite / urls.py文件的样子:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)
当我浏览到服务器URL时,我得到了这个回复:
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:
1. ^admin/doc/
2. ^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.
我做错了什么?
答案 0 :(得分:12)
要查看管理页面访问,请访问“http://127.0.0.1:8000/admin/”
当你有管理员网址
时# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# (r'^admin/', include(admin.site.urls)),
评论,没有其他网址,django欢迎页面默认显示在'http://127.0.0.1:8000/'
答案 1 :(得分:4)
Request URL: http://127.0.0.1:8000/
您正在访问 root 网址。但是,您没有与此匹配的URL配置。您的管理员应用位于http://127.0.0.1:8000/admin/
。试试吧。
如果您希望root用户可以访问管理员应用,则必须更改您的网址映射,如下所示:
urlpatterns = patterns('',
# Uncomment the next line to enable the admin:
(r'^$', include(admin.site.urls)),
)
请注意,不建议这样做。您当然不希望根URL指向管理员应用程序!
答案 2 :(得分:0)