I am using Django's default password reset views and forms to send an email to the user for them to reset their password via a link in the email. I have most of the development complete but am stuck on one issue. When I receive the email from the local host, I click the link, enter my new password 2 times, hit 'submit' and get this error: Error Message.
Below is my code. urls.py
"""defines URL patterns for users"""
from django.urls import path, include, reverse_lazy
from django.contrib.auth import views as auth_views
from . import views
app_name = 'users'
urlpatterns = [
# include all default auth urls
path('', include('django.contrib.auth.urls')),
path('register/', views.register, name='register'),
path(
'reset_password/',
auth_views.PasswordResetView.as_view(
template_name='registration/password_reset.html',
success_url=reverse_lazy('users:password_reset_done')
) ,
name='reset_password'
),
path(
'reset/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(
template_name='registration/password_reset_form.html',
success_url=reverse_lazy('users:password_reset_complete')
),
name='password_reset_confirm'
),
path(
'password_reset_done/',
auth_views.PasswordResetDoneView.as_view(
template_name="registration/password_reset_sent.html"),
name='password_reset_done'
),
path(
'password_reset_complete/',
auth_views.PasswordResetCompleteView.as_view(
template_name='registration/password_reset_done.html'),
name='password_reset_complete'
),
path('forgot_username/', views.forgot_username, name="forgot_username"),
path('username_retrieval/', views.username_retrieval, name="username_retrieval"),
]
As you can see, I am using the namespace 'users' in the success_url variable, however, it seems to work on the reset_password
path, but it does not seem to work on the reset/<uidb64>/<token>
path.
One thing to be aware of is that I have a custom user model in my application. Would that affect my ability to use this default Django password reset method?
In addition, here are my templates under the users/templates/registration/ folder: User App Templates
Some other things to mention:
When I click on the link from my email, I am directed to password_reset_confirm
and not password_reset_form
so that tells me that the template name is not being overwritten as well.
When I change
success_url=reverse_lazy('users:password_reset_complete')
to
success_url=reverse_lazy('users:password_reset_completed')
the app doesn't look for users:password_reset_completed
so that implies that the success_url
is not being overwritten.
Any help would be appreciated and I can post more code and answer questions if necessary.
Thanks in advance!
CodePudding user response:
this line is overwriting all your paths:
path('', include('django.contrib.auth.urls')),
just remove it or if you want to keep some of them place it at the end after your paths