简体   繁体   English

django url没有反向匹配

[英]django url no reverse match

I am trying to pass two parameters through the url in django (email,name) it works fine when I am just passing the email through but when I pass the name through as well I get an error (no reverse match) my name contains a space 我正在尝试通过django中的url(电子邮件,名称)传递两个参数,当我只是通过电子邮件传递时,它可以正常工作,但是当我通过名称传递时,我也会收到一个错误(无反向匹配),我的名称包含一个空间

url pattern 网址格式

url(r'^details/(?P<email>[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/(?P<name>([\W ]+))/$', details, name="details")

full error message 完整的错误信息

Reverse for 'password' with arguments '(u'tom@example.com', u'tom')' and keyword arguments '{}' not found. 1 pattern(s) tried: ['details/(?P<email>[\\\\w.%+-]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,4})/(?P<name>([\\\\W ]+))/ Reverse for 'password' with arguments '(u'tom@example.com', u'tom')' and keyword arguments '{}' not found. 1 pattern(s) tried: ['details/(?P<email>[\\\\w.%+-]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,4})/(?P<name>([\\\\W ]+))/ $ Reverse for 'password' with arguments '(u'tom@example.com', u'tom')' and keyword arguments '{}' not found. 1 pattern(s) tried: ['details/(?P<email>[\\\\w.%+-]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,4})/(?P<name>([\\\\W ]+))/ $

passing variable through to the url 将变量传递到url

{%url 'details' email name %}

What is the exact error you are getting. 您得到的确切错误是什么。 When working with multiple variable you can try the following. 使用多个变量时,可以尝试以下操作。

{%url 'details' email=email name=name %}

Update: 更新:

url(r'^details/(?P<email>[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/(?P<name>([\W ]+))/$', details, name="details")

You probably want to change 你可能想改变

(?P<name>(\W+))  # non-alphanumeric

to

(?P<name>\w+)  # alphanumeric

The upper-case version is, one would assume, the exact opposite of what you want to allow for names (and urls in general). 假设是大写版本,则与您要允许使用的名称(通常是url)完全相反。

Python regex syntax docs. Python regex语法文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM