Reverse Not Found Error
Asked Answered
T

2

7

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.

Touchdown answered 19/12, 2013 at 20:24 Comment(10)
What is your Django version?Lightman
And you're able to visit the URL in the website fine?Lightman
Try debugging in a shell with from django.core.urlresolvers import reverse and then reverse('reset_password', kwargs={'uid':uid, 'token':token}) see if you get more info. Also, if your url conf is part of an app, make sure it's included in the main url conf.Syblesybley
it sends me back the proper url (/reset/uid/token/) when I run it in the console.Touchdown
Are you sure you have a valid values in uid and token variables in context in your template?Flavescent
How are you receiving values in those variables? Can you provide some code relating to it?Variometer
my guess is that token and or uid variables do not exist in the context, try showing them, adding this somewhere else on the same template {{token|pprint}} {{uid|pprint}}Hudnall
Can you output the uuid and token format? do they actually get matched at the regexp? Usually this error happens if the pattern does not match the arguments.Contemn
In Django 1.6 therse are : uidb64,token . And try to add comma in your arguments. Try that like this: url 'reset_password' uid64=uid,token=token .Residential
Solved? If not please show your urls.py...Aeolipile
R
1

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...

Resnatron answered 7/1, 2014 at 11:20 Comment(0)
O
1

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'

Oestrin answered 14/2, 2018 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.