Mphoza
Mphoza

Reputation: 117

'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name

I keep getting this error:

NoReverseMatch at /accounts/password_reset/ Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name

The following is my code so far:

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


app_name = 'accounts'

urlpatterns = [
    url(r'^login/$', views.login_view, name='login_view'),
    url(r'^register_view/$', views.register_view, name='register_view'),
    url(r'^logout/$', views.logout_view, name="logout_view"),
    url(r'^profile_view/$', views.profile_view, name="profile_view"),
    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='registration/password_reset_form.html',email_template_name='registration/password_reset_email.html',subject_template_name='registration/password_reset_email.txt',success_url='/accounts/password_reset_done/',from_email='[email protected]')),
    url(r'password_reset_done/',auth_views.PasswordResetDoneView.as_view(template_name='registration/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='registration/password_reset_confirm.html',success_url='/accounts/password_reset_confirm/'), name='password_reset_confirm'),
    url(r'password_reset_complete/',auth_views.PasswordResetCompleteView.as_view(template_name='registration/password_reset_complete.html')),
]

Upvotes: 3

Views: 12646

Answers (3)

dexter
dexter

Reputation: 1

Instead of writing it like this

reset_password
reset_password_done
reset_password_confirm
reset_password_complete

You need to write it this way

reset_password
password_reset_done
password_reset_confirm
password_reset_complete

it worked for me.

Upvotes: 0

MOham&#233;d ABkasm
MOham&#233;d ABkasm

Reputation: 71

You need to know that django uses the default template for the email message subject which is (password_reset_email.html) under the name password_reset_confirm, but your are using a namespace, acocunts:password_reset_confirm, all what you need to do is

  1. Override the template path using this attr email_template_name
auth_views.PasswordResetView.as_view(
  template_name ='accounts/registration/password_reset.html',
  email_template_name = 'accounts/registration/password_reset_email.html'),
  1. Set up your email configurations in settings.py to send your email, without getting a error (Errno 111) connection refused

Upvotes: 7

Alasdair
Alasdair

Reputation: 308869

To get Django to use your app's registration/password_reset_form.html' template, you need to move that app above django.contrib.admin in your INSTALLED_APPS setting.

Note that Django doesn't make it easy to use a namespace with the password reset views. Once you have fixed this NoReverseMatch, you may find you have to fix similar errors. It would probably be easier to move your password reset URL patterns into a urls.py that does not have a namespace.

Upvotes: 5

Related Questions