简体   繁体   中英

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

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 ]+))/ $

passing variable through to the 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).

Python regex syntax docs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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