Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django reset_password_confirm TemplateSyntaxError problem

when I use django.contrib.auth.views.password_reset_confirm without arguments at all it works and I can render the template without any problem, when adding uidb36 and token arguments it fails.

Caught NoReverseMatch while rendering: Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{'uidb36': '111', 'token': '1111111111111'}' not found.

like image 608
Afiku Avatar asked Jan 25 '11 07:01

Afiku


3 Answers

Most likely it is an issue with your urls.py. You need to setup the right pattern to grab the uidb36 and token values passed as URL parameters. If not, it will throw a similar error to what you see above.

Something like:

(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm', {'template_name' : 'registration/password_reset.html',  'post_reset_redirect': '/logout/' })

registration/password_reset.html - is my custom template

logout - is my custom logout action

like image 126
Chris Wherry Avatar answered Nov 05 '22 04:11

Chris Wherry


I had this issue in Django 1.3, and wasted a lot of time because the error can mask a number of underlying issues.

I needed to add this to the top of the reset email template:

{% load url from future %}

Also, the example in the Django docs didn't match the sample url:

{{ protocol}}://{{ domain }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %}

So I had to change the auth_password_reset_confirm above to password_reset_confirm.

like image 30
greg Avatar answered Nov 05 '22 03:11

greg


If you're using Django 1.6+ and run into something like this it could be that you need to update uidb36 to uidb64 in both your template and your urls.

Example url: url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', auth_views.password_reset_confirm

and reset link in template:

{{ protocol}}://{{ domain }}{% url 'django.contrib.auth.views.password_reset_confirm' uidb64=uid token=token %}

like image 6
iepathos Avatar answered Nov 05 '22 05:11

iepathos