[英]Django url doesn't match even though it should
In browser I get: Request URL: http://xxxxxx:8000/person/test/ 在浏览器中,我得到:请求URL: http:// xxxxxx:8000 / person / test /
Using the URLconf defined in person.urls, Django tried these URL patterns, in this order: Django使用person.urls中定义的URLconf,按以下顺序尝试了以下URL模式:
^person/ ^$
^person/ ^person/(?P<slug>[-\\w]+)/$
^admin/
The current URL, person/test/
, didn't match any of these. 当前网址person/test/
与此不匹配。
In python shell I get: 在python shell中,我得到:
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. 仅使用url person /(^ $正则表达式)即可。
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]+)/$'
它与r'^person/(?P<slug>[-\\w]+)/$'
不匹配,404页面显示它与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. 您可能已经在urls.py中匹配了^person/
,然后导入了另一个urls.py并在其中也放置了“ person”。 Remove it from the second urls.py. 从第二个urls.py中删除它。 After importing, a secondary urls.py only has to match the rest of the URL, not the whole URL. 导入后,辅助urls.py只需要匹配其余URL,而不是整个URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.