【发布时间】:2011-05-16 14:19:16
【问题描述】:
我曾经有一个 urls 文件看起来像这样:
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
url(r'^$', 'girls.views.home', name = 'home'),
url(r'^registerasboy$', 'girls.views.regb', name= 'regb'),
#url(r'^registerasgirl$', 'girls.views.reg', name= 'regg'),
url(r'^thankyou$', 'girls.views.thankyou', name= 'thankyou'),
url(r'^newchick$', 'girls.views.newchick', name= 'newchick'),
url(r'^chicks$', 'girls.views.chicks', name= 'chicks'),
#url(r'^thankyou$', 'generalsettings.views.thankyou', name = 'thankyou'),
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
#url(r'^reg$', 'generalsettings.views.home'),
# Uncomment the next line to enable the admin:
#(r'^admin/', include(admin.site.urls)),
#(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)
并且该网站有效。我没有管理员。所以我决定取消注释管理行,我会得到错误 404
找不到页面 (404)
请求方法:GET
请求网址:http://chicklister.com/admin
Using the URLconf defined in chick.urls, Django tried these URL patterns,
in this order:
^$ [name='home']
^registerasboy$ [name='regb']
^thankyou$ [name='thankyou']
^newchick$ [name='newchick']
^chicks$ [name='chicks']
^/(?P<path>.*)$
The current URL, admin, didn't match any of these.
这很奇怪,因为这里缺少管理行。现在,我将我的网址进一步更新为:
urlpatterns = 模式('',
(r'^admin/', 包括(admin.site.urls)),)
但我得到了管理员:
Using the URLconf defined in chick.urls, Django tried these URL patterns,
in this order:
^$ [name='home']
^registerasboy$ [name='regb']
^thankyou$ [name='thankyou']
^newchick$ [name='newchick']
^chicks$ [name='chicks']
^/(?P<path>.*)$
The current URL, admin, didn't match any of these.
然而,根据打印的 url 文件中的行,任何其他 url 都可以使用,例如 www.domain.com/thankyou
这怎么可能?好像在什么地方被记住了。
我做的步骤: 在 www 中的整个文件夹中搜索“registerasboy”并不再返回任何内容。 我更改了模板上的文本,以确保我正在更新正确的副本。 我在 settings.py 中有以下设置:
ROOT_URLCONF = '网址' 我注意到它并没有真正做任何事情,因为一开始它是chic.urls
我做错了什么?我似乎连这样的文件都没有了……
【问题讨论】:
标签: python django url settings