我已经在其他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$
,则URL membres.html
正常工作并加载视图...
r'^/(?P<slug>\d+)\.html$
怎么了?
非常感谢
python大神给出的解决方案
\d+
仅匹配数字。 nicolas
不是由数字组成。
\w+
是您要寻找的。
通常,[\w-]+
表示通常包含连字符的段符。