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

Another NoReverseMatch at / accounts / password / reset / question. I tried so many different solutions and nothing works for me. BTW I don't get an error if I try to use a random password that is not in the DB.

Django 1.6

Mistake

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 %}

      

This is a link inside the password_reset_email.html template as I receive an email and don't get an error if I remove the link.

+3


source to share


2 answers


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

+2


source


If you are using Django 1.6 as you indicate that the code you are using is incorrect as the 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 should change the pattern for your reset password accordingly.

You should also change the URLs accordingly.



Now you

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/'}),

      

There 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'),

      

0


source







All Articles