2π
β
The culprit is the app_name = 'accounts'
. This means that the success_url
that is defined in the PasswordResetView
, which points to a view with the name password_reset_done
thus no longer can find its view. The same will happen with the PasswordResetConfirmView
.
You can override this with the name of the view that contains the namespace prefix:
from django.urls import path, reverse
from .views import *
from django.contrib.auth import views as auth_views
# namespace β (view names need to be prefixed with 'accounts:')
app_name = 'accounts'
urlpatterns = [
path('create-user/', registerview, name='register'),
path('login/', loginview, name='login'),
path('logout/', logoutview, name='logout'),
path(
'password_reset/',
auth_views.PasswordResetView.as_view(
template_name='accounts/reset_password.html'
success_url=reverse_lazy('accounts:password_reset_done')
),
name='password_reset'
),
path('password_reset_done/', auth_views.PasswordResetDoneView.as_view(template_name='accounts/reset_password_sent.html'), name='password_reset_done'),
path(
'password_reset/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(
template_name='accounts/reset_password_form.html'
success_url=reverse_lazy('accounts:password_reset_complete')
),
name='password_reset_confirm'
),
path('password_reset_complete/', auth_views.PasswordResetCompleteView.as_view(template_name='accounts/reset_password_sucess.html'), name='password_reset_complete'),
]
In the template, you should also prefix it with the namespace, so:
{% url 'account:password_reset_confirm' uidb64=uid token=token %}
If this is the builtin template, you can create your own template, for example by copy pasting the original template [GitHub] and then save a new template and specify the path that that template with:
from django.urls import path, reverse
from .views import *
from django.contrib.auth import views as auth_views
# namespace β (view names need to be prefixed with 'accounts:')
app_name = 'accounts'
urlpatterns = [
path('create-user/', registerview, name='register'),
path('login/', loginview, name='login'),
path('logout/', logoutview, name='logout'),
path(
'password_reset/',
auth_views.PasswordResetView.as_view(
template_name='accounts/reset_password.html',
success_url=reverse_lazy('accounts:password_reset_done'),
email_template_name='path_to/template.html'
),
name='password_reset'
),
path('password_reset_done/', auth_views.PasswordResetDoneView.as_view(template_name='accounts/reset_password_sent.html'), name='password_reset_done'),
path(
'password_reset/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(
template_name='accounts/reset_password_form.html'
success_url=reverse_lazy('accounts:password_reset_complete')
),
name='password_reset_confirm'
),
path('password_reset_complete/', auth_views.PasswordResetCompleteView.as_view(template_name='accounts/reset_password_sucess.html'), name='password_reset_complete'),
]
Source:stackexchange.com