Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

django-views

I keep getting this error Reverse for 'password_reset_done' not found. 'password_reset_done' is not a valid view function or pattern name. i am trying to use the default view from from django.contrib.auth.views

from django.conf.urls import url 
from accounts import views 
from django.contrib.auth.views import (login, 
logout, 
password_reset, 
password_reset_done, 
password_reset_confirm, 
) 


urlpatterns =[ 
url(r'^$', views.cover, name='cover'), 
url(r'^home/$', views.home, name = 'home'), 
url(r'^login/$', login, {'template_name':'accounts/login.html'}, name ="login"), 
url(r'^logout/$', logout, {'template_name':'accounts/logout.html'}, name = "logout"), # views define a link to connecct this to views then to template 
url(r'^register/$', views.register, name="register"), 
url(r'^profile/$', views.view_profile, name='view_profile'), 
url(r'^profile/edit/$', views.edit_profile, name='edit_profile'), 
url(r'^change-password/$', views.change_password, name='change_password'), 
url(r'^reset-password/$', password_reset, name= 'password_reset'), 
url(r'^reset-password/done/$', password_reset_done, name='password_reset_done'), 
url(r'^reset-password/confirm/$', password_reset_confirm, name='password_reset_confirm') 
]

Please anybody help me out... i have check all... but couldnt find the fault.

like image 845
Nitish Kumar Pal Avatar asked Jun 21 '17 12:06

Nitish Kumar Pal


4 Answers

it'll work if you just use path('', include('django.contrib.auth.urls')) in your main urls.py not the one in your app_name.

like image 127
SaEED AB Avatar answered Jan 04 '23 00:01

SaEED AB


plz try this be carefull to watch for some errors like not adding the $ at the end of some urls or maybe adding it. also pay attention to where success_url is given because the internal code uses it and is lost without it.

here in this code the application that I chose to manage users is called accounts, you can call yours anything.

the templates should be put inside a directory that is recognized by django otherwise it won't find them here is the code for settings.py

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'),],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

and here is the full urls.py

from django.conf.urls import url
from django.contrib.auth import views as auth_views
from accounts.views import signup

urlpatterns = [
    url(r'signup/$', signup, name='signup'),
    url(r'login/$',auth_views.LoginView.as_view(template_name='login.html')),
    url(r'logout/$',auth_views.LogoutView.as_view(template_name='logout.html')),
    url(r'password_change/$',auth_views.PasswordChangeView.as_view(template_name='password_change.html',success_url='/accounts/password_change_done')),
    url(r'password_change_done/',auth_views.PasswordChangeDoneView.as_view(template_name='password_change_done.html')),
    url(r'password_reset/$',auth_views.PasswordResetView.as_view(template_name='password_reset.html',email_template_name='password_reset_email.html',subject_template_name='password_reset_subject.txt',success_url='/accounts/password_reset_done/',from_email='[email protected]')),
    url(r'password_reset_done/',auth_views.PasswordResetDoneView.as_view(template_name='password_reset_done.html')),
    url(r'password_reset_confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',auth_views.PasswordResetConfirmView.as_view(template_name='password_reset_confirm.html',success_url='/accounts/password_reset_complete/')),
    url(r'password_reset_complete/',auth_views.PasswordResetCompleteView.as_view(template_name='password_reset_complete.html')),
]
like image 33
khamlichi.khalil Avatar answered Jan 03 '23 22:01

khamlichi.khalil


I had the same problem but solved it by adding the success_url parameter in PasswordResetView :

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

url(r'^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 24
David Avatar answered Jan 03 '23 22:01

David


These occurs when Django is updated from 1.xx to 2.xx (well, as in my own case).

This is my solution. I fixed it by including a dictionary with key "post_change_redirect" with it's value pointing to the password_change_done url. For password resetting use post_rest_redirect.

from django.contrib.auth import views as v
from django.conf.urls import url

urlpatterns = 
......
    url(r"password-change/$", v.password_change, {"post_change_redirect":"account:password_change_done"}, name="password_change")
.........

]
like image 31
Faisal Lawan Avatar answered Jan 03 '23 22:01

Faisal Lawan