【发布时间】:2015-03-14 05:52:16
【问题描述】:
我已经在其他 stackoverflow 线程上检查过这个错误,但在我的代码中没有发现任何错误。也许我累了,但我觉得还可以。
website.urls.py:
from django.conf.urls import patterns, include, url
#from django.contrib import admin
urlpatterns = patterns('',
# Register and Login
url(r'^inscription\.html$', 'membres.views.register'),
# List of users
url(r'^membres', include('membres.urls')),
)
membres.urls.py:
from django.conf.urls import patterns, url
urlpatterns = patterns('membres.views',
url(r'^/(?P<slug>\d+)\.html$', 'view_user_public')
)
我当然明白了:
Using the URLconf defined in website.urls, Django tried these URL patterns, in this order:
^inscription\.html$
^membres ^/(?P<slug>\d+)\.html$
The current URL, membres/nicolas.html, didn't match any of these.
inscription.html 可以正常工作。在membres.urls.py 文件中,如果我将r'^/(?P<slug>\d+)\.html$ 更改为r'^\.html$,则网址membres.html 可以正常工作并加载视图...
r'^/(?P<slug>\d+)\.html$ 有什么问题?
非常感谢
【问题讨论】:
-
尝试删除网址开头的
^。这意味着“字符串的开头”,它不会匹配(因为字符串以membres开头。 -
为什么每个 URL 都以
.html结尾?没必要这么做。 -
因为这样我才能找到漂亮的 URL :)。
标签: python django django-urls