Django url doesn't match even though it should
In browser I get: Request URL: http://xxxxxx:8000/per开发者_运维百科son/test/
Using the URLconf defined in person.urls, Django tried these URL patterns, in this order:
^person/ ^$
^person/ ^person/(?P<slug>[-\w]+)/$
^admin/
The current URL, person/test/
, didn't match any of these.
In python shell I get:
import re
url = 'person/test/'
pattern = re.compile(r'^person/(?P<slug>[-\w]+)/$'
re.match(pattern,url)
<_sre.SRE_Match object at 0xb7716860>
So it obviously should match the regexp. Using only url person/ (the ^$ regexp) does work.
I've tried restarting the development server of course. What could be wrong here?
It isn't matching against r'^person/(?P<slug>[-\w]+)/$'
, the 404 page shows that it's matching against r'^person/person/(?P<slug>[-\w]+)/$'
You've probably matched ^person/
in a urls.py, then imported another urls.py and put "person" in there also. Remove it from the second urls.py. After importing, a secondary urls.py only has to match the rest of the URL, not the whole URL.
精彩评论