WayBehind
WayBehind

Reputation: 1697

Django NoReverseMatch at /accounts/password/reset/ for password reset

Just another NoReverseMatch at /accounts/password/reset/ question. I have tried so many different solutions and nothing is working for me. BTW I get no error if I try a random password that is not in the DB.

Django 1.6

Error

NoReverseMatch at /accounts/password/reset/
Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb64': 'Mg', u'token': u'3vb-60fc793f1a685844bbe1'}' not found. 0 pattern(s) tried: []

Error during template rendering

In template /home/jr/Documents/python/amapp1/local/lib/python2.7/site-packages/django/contrib/admin/templates/registration/password_reset_email.html, error at line 7
Reverse for 'django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments '{u'uidb64': 'Mg', u'token': u'3vb-60fc793f1a685844bbe1'}' not found. 0 pattern(s) tried: []

urls.py

from django.conf.urls import patterns, url
from django.contrib.auth.views import login, password_reset, password_reset_confirm, password_reset_done, password_reset_complete

url(r'^password/reset/$', 'django.contrib.auth.views.password_reset',
 {'post_reset_redirect' : '/accounts/password/reset/done/'}),
url(r'^password/reset/done/$', 'django.contrib.auth.views.password_reset_done'),
url(r'^password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm',
 {'post_reset_redirect' : '/accounts/password/done/'}),
url(r'^password/done/$', 'django.contrib.auth.views.password_reset_complete'),

password_reset_email.html

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

It is the link inside the password_reset_email.html template as I do receive the email and get no error if I remove the link.

Upvotes: 3

Views: 2948

Answers (2)

Ales Maticic
Ales Maticic

Reputation: 1965

If you are using Django 1.6 as you are stating than the code you are using is wrong as password reset was changed in Django 1.6.

Please read here https://docs.djangoproject.com/en/1.7/topics/auth/default/#django.contrib.auth.views.password_reset

You must change the template for your password reset email accordingly.

You must also change the urls accordingly

You have now

url(r'^password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm',
 {'post_reset_redirect' : '/accounts/password/done/'}),

Should be something like this

url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
    'django.contrib.auth.views.password_reset_confirm',
    name='password_reset_confirm'),

Upvotes: 0

teewuane
teewuane

Reputation: 5734

Change the url in your password_reset_email.html to:

{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}

This is how it is done in the docs

Upvotes: 3

Related Questions