I'm working on authentication for a Django project I'm working on. For some reasons, I'm getting the error Reverse for 'password_reset_done' not found. 'password_reset_done' is not a valid view function or pattern name. I put everything authentication in an accounts app.
Here's the content of the base urls.py file:
from django.contrib import admin
from django.urls import path, include
from accounts import urls as accounts_urls
from core import urls as core_urls
from core import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name='home'),
path('accounts/', include(accounts_urls, namespace='accounts')),
path('core/', include(core_urls, namespace='core')),
]
Here's the content of the urls.py file (in the accounts app):
from django.urls import path, reverse_lazy
from django.contrib.auth import views as auth_views
from . import views as accounts_views
app_name = 'accounts'
urlpatterns = [
path('signup/', accounts_views.signup, name='signup'),
path('login/', auth_views.LoginView.as_view(template_name='accounts/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
path('account_activation_sent/', accounts_views.account_activation_sent, name='account_activation_sent'),
path('activate/<uidb64>/<token>/', accounts_views.activate, name='activate'),
path('password_reset/', auth_views.PasswordResetView.as_view(
template_name='accounts/password_reset.html',
email_template_name='accounts/password_reset_email.html',
subject_template_name='accounts/password_reset_subject.txt'
), name='password_reset'),
path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(
template_name='accounts/password_reset_done.html'
), name='password_reset_done'),
path('password_reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(
template_name='accounts/password_reset_confirm.html'
), name='password_reset_confirm'),
path('password_reset/complete/', auth_views.PasswordResetCompleteView.as_view(
template_name='accounts/password_reset_complete.html'
), name='password_reset_complete'),
]
Here's the accounts/templates directory structure:
I don't see anything wrong with what I have done so far. Any eye opener would be greatly appreciated, thanks!
I figured it out! Since I wanted to have more control over URLs, I changed the default Password Reset patterns. I was also bent on using namespaces so I changed the default success_url attribute in PasswordResetView and PasswordResetConfirmView to use the namespace. Here's what I mean:
from django.urls import path, reverse_lazy, include
from django.contrib.auth import views as auth_views
# Add other necessary imports
app_name = 'accounts'
urlpatterns = [
path('password_reset/', auth_views.PasswordResetView.as_view(
template_name='accounts/password_reset.html',
email_template_name='accounts/password_reset_email.html',
subject_template_name='accounts/password_reset_subject.txt',
success_url=reverse_lazy('accounts:password_reset_done')
), name='password_reset'),
path('password_reset_done/', auth_views.PasswordResetDoneView.as_view(
template_name='accounts/password_reset_done.html'
), name='password_reset_done'),
path('password_reset_<uidb64>_<token>/', auth_views.PasswordResetConfirmView.as_view(
template_name='accounts/password_reset_confirm.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/password_reset_complete.html'
), name='password_reset_complete'),
]
Caspian I believe, you found the solution to my problem,
Moving from Django 2.0 to 2.1, I was going nuts trying to correct my password app to the new required configuration... I could not understand the problem... I did not improve on your solution, but here are my URL codes and it does confirm introducing "success_url=reverse_lazy" your solution works great.
path('password_reset/',
PasswordResetView.as_view(
template_name='app98/password_reset.html',
email_template_name='app98/password_reset_email.html',
subject_template_name='app98/password_reset_subject.txt',
success_url=reverse_lazy('ns_app98:password_reset_done')),
name='password_reset'),
path('password_reset_done/',
PasswordResetDoneView.as_view(
template_name='app98/password_reset_done.html'),
name='password_reset_done'),
path('password_reset_<uidb64>_<token>/',
PasswordResetConfirmView.as_view(
template_name='app98/password_reset_confirm.html',
success_url=reverse_lazy('app98:password_reset_complete')),
name='password_reset_confirm'),
path('password_reset_complete/',
PasswordResetCompleteView.as_view(
template_name='app98/password_reset_complete.html'),
name='password_reset_complete'),
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With