简体   繁体   English

Django网址不匹配,即使应该匹配

[英]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.

相关问题 RegEX似乎不匹配,即使它应该匹配 - RegEX doesn't seem to match, even though it should django 找不到 url 即使它在那里 - django can't find url even though it is there Python正则表达式库即使匹配也无法匹配 - Python regex library can't match even though it should 文本与文件文本不匹配,即使它匹配 Tkinter - Text doesn't match the file text even though it does Tkinter 即使url更改,Django模板也不会加载 - Django templates don't load, even though the url changes 在 azure 管道中运行 python unittests 不会失败,即使它应该 - Running python unittests in azure pipeline doesn't fail even though it should django 错误,即使我允许 url 中的属性它不起作用 - django error where even though i allowed an attribute in url it isn't working Django URL 出现 404 错误,即使它包含在 url 模式中 - 404 Error with Django URL even though it is included in url patterns Django ORM,即使获取了过滤条件,也不符合条件的数据 - Django ORM, data that does not match the condition even though filtering is acquired IronPython为什么不支持SQLite3的预写日志记录,即使它的SQLite版本也应如此? - Why doesn't IronPython support SQLite3's Write-Ahead Logging, even though its SQLite version should?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM