Reverse Not Found Error

682 Views Asked by At

If I have a URL Like this:

url(r'^reset/(?P<uid>\w+)/(?P<token>\w+)/$', 'django.contrib.auth.views.password_reset_confirm', name="reset_password")

and a URL tag like this:

{% url 'reset_password' uid=uid token=token %}

Why do I get this error when I try to render the page in which the tag is contained:

Reverse for 'reset_password' with arguments '()' and keyword arguments not found 

The both the uid and token are valid strings.

2

There are 2 best solutions below

0
Viroide On

I would say that your uid or your token has a non alphanumerical char like "-" or "." So I would try to change the urls.py to:

url(r'^reset/(?P<uid>.+)/(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm', name="reset_password")

I don't like using the . in regex but If you have not oteher choices...

0
rash On

try the following:

1.always try to namespace your url like'app_name:reset_password' with adding just

app_name='your app name' at the beginning of your urls.py file this will help you in future if you are handling multiple apps in same project when the names of your html are conflicting at same time

2.try this changes in your urls , as you are using django auth views and its password reset function you need specify redirect url also after resetting your password for that just add

{'post_reset_redirect':'<app_name>:<url_name>'}

url(r'^reset/(?P<uid>[-\w]+)/(?P<token>[-\w]+)/$', 'django.contrib.auth.views.password_reset_confirm', {'post_reset_redirect':'<your redirection url after reset password'},name="reset_password")}

And yes please check the variables also like 'uid' because as it is django's own function might be it own variable name so try 'uidb64'