Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse for 'password_reset_done' not found. 'password_reset_done' is not a valid view function or pattern name

Tags:

python

django

I have a problem with django's view "password_reset_done". When I try to open accounts/reset-password I have this error. But if I open url accounts/reset-password/done it works.

URLS.PY of "accounts" app

from django.conf.urls import url
from django.contrib.auth.views import login , logout, password_reset, 
    password_reset_done
from . import views

urlpatterns = [
    url(r'^register/$', views.register, name='register'),
    url(r'^profile/$', views.profile, name='profile'),
    url(r'^profile/prpage/(\d+)/$', views.profile, name='prpage'),
    url(r'^profile-edit/$', views.profiledit, name='profile-edit'),
    url(r'^login/$', login ,{'template_name':'accounts/login.html'}, 
        name='login'),
    url(r'^logout/$', views.logout_view, name='logout'),
    url(r'^profile/(?P<proj_id>\d+)/$', views.userprojectpage, 
        name='userprojectpage'),
    url(r'^changepassword/$', views.changepassword, name='changepassword'),
    url(r'^reset-password/$', password_reset, name='reset_password'),
    url(r'^reset-password/done/$', password_reset_done, 
        name='password_reset_done'),
] 

please help! Thanks in advance)

like image 207
beka Avatar asked Oct 31 '17 10:10

beka


2 Answers

Add success_url parameter of Class Based View PasswordResetView. This will replace default route of password_reset_done

from django.urls import path, re_path, include, reverse_lazy

path('reset/',PasswordResetView.as_view(

        template_name='password_reset.html',
        email_template_name='password_reset_email.html',
        subject_template_name='password_reset_subject.txt',
        ...
    
        success_url = reverse_lazy('accounts:password_reset_done')

        ...
        ... 
        ),name='password_reset'),

like image 68
koderstory Avatar answered Oct 03 '22 11:10

koderstory


11 there are some change made look like password_reset, password_reset_done not able to import therefore display this error regarding this url https://github.com/django/django/blob/stable/1.11.x/django/contrib/auth/views.py.

There are two way to resolve the error above.

  1. to resolve this error add url(r'', include('django.contrib.auth.urls')), to main urls.py in your project. This will stopped the error and keep your urls in your accounts: url(r'^reset-password/$', password_reset, name='reset_password'), url(r'^reset-password/done/$', password_reset_done, name='password_reset_done'), I have resolved this error like above and it works fine.

  2. Second way to resolve the error is different than first option above,remove the url(r'', include('django.contrib.auth.urls')), from main urls.py file and in your accounts/urls.py add following url's: url(r'^reset-password/$', password_reset, {'template_name':'reset_password.html', 'post_reset_redirect':'accounts:password_reset_done', 'email_template_name': 'reset_password_email.html'}, name='reset_password'),

    url(r'^reset-password/done/$', password_reset_done, {'template_name': 'reset_password_done.html'}, name='password_reset_done'),

    url(r'^reset-password/confirm/(?P[0-9A-Za-z]+)-(?P.+)/$', password_reset_confirm, {'template_name': 'reset_password_confirm.html', 'post_reset_redirect':'accounts:password_reset_complete'}, name='password_reset_confirm'),

This is the second solution and working.

I hope that helps your problem and sorry for delay respond your last comment, I was away.

DilMac

like image 26
DilMac Avatar answered Oct 03 '22 13:10

DilMac