[英]url captured regex (\w+) not matching certain urls
The two lines of the urls.py config file for my_app
are shown below. my_app
的urls.py配置文件的两行如下所示。 They're almost the same, only the second has a uuid4 appended to it 它们几乎相同,只有第二个附加了uuid4
# preview views to allow us to preview stuff
url(r'^(?P<hash>\w+)/preview/$', Start.as_view(), {'preview':True}, name='preview'),
url(r'^(?P<hash>\w+)/preview/(?P<uuid>[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12})/$', PreviewController.as_view(), name='previewcontroller'),
The following urls work without error: 以下网址可以正常工作:
The following urls yield the below error (all hash
values are valid, but that shouldn't affect the url resolution): 以下网址产生以下错误(所有
hash
值均有效,但这不应影响网址解析):
Internal Server Error: /my_app/841211121/preview/
内部服务器错误:/ my_app / 841211121 / preview /
NoReverseMatch at /my_app/841211121/preview/ Reverse for 'previewcontroller' with arguments '()' and keyword arguments '{'uuid': None, 'hash': '841211121'}' not found.
/ my_app / 841211121 / preview /上的NoReverseMatch与具有参数'()'和关键字参数'{'uuid':None,'hash':'841211121'}'的'previewcontroller'反向。 1 pattern(s) tried: ['my_app/(?P\\w+)/preview/(?P[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12})/$']
尝试了1个模式:['my_app /(?P \\ w +)/ preview /(?P [a-f0-9] {8}-?[a-f0-9] {4}-?4 [a -f0-9] {3}-?[89ab] [a-f0-9] {3}-?[a-f0-9] {12})/ $']
Request Method: GET Request URL: http://example.com/my_app/841211121/preview/ Django Version: 1.10...
请求方法:GET请求URL: http : //example.com/my_app/841211121/preview/ Django版本:1.10 ...
Regex101.com says that the url should match (with escaped slashes, of course). Regex101.com表示该网址应匹配(当然,应带有转义的斜杠)。 Why on earth are the second group of urls not matching the
preview
url, and what is provoking the url resolver to attempt to match them to previewcontroller
when there is no uuid
string appended to the url? 到底为什么第二组URL与
preview
URL不匹配previewcontroller
当没有uuid
字符串附加到URL时,是什么激起了URL解析器尝试将它们与previewcontroller
匹配?
Django is correctly resolving the /my_app/841211121/preview/
and running the correct view. Django正在正确解析
/my_app/841211121/preview/
并运行正确的视图。
The problem is occurring when Django runs the Start
view. Django运行“
Start
视图时发生此问题。 It looks like a reverse()
call or {% url %}
template tag is failing. 看来是
reverse()
调用或{% url %}
模板标记失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.