Reputation: 179
What I'm trying to do is overwrite the default HTML templates that django uses for password_reset, password_reset_done, password_reset_confirm,and password_reset_complete. When I added a custom template to the first URL (password_reset) it actually worked perfectly. I could type the email that's associated with the user and proceed with the reset process, but when I tried to add a custom template for the password_reset_done view, the password_reset view no longer works and I get the following error:
Reverse for 'password_reset_done' not found. 'password_reset_done' is not a valid view function or pattern name.
Here's my urls.py:
from django.conf.urls import url
# imports for views at a gloabl level (aka other django apps)
from . import views
from django.contrib.auth.views import (
login,
logout,
password_reset,
password_reset_done,
password_reset_confirm,
password_reset_complete
)
urlpatterns = [
url(r'^$', views.home),
url(r'^login/$', login, {'template_name': 'accounts/login.html'}),
url(r'^logout/$', logout, {'template_name': 'accounts/logout.html'}),
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, {'template_name': 'accounts/reset_password.html'}),
url(r'^reset-password/done/$', password_reset_done, {'template_name': 'accounts/password_reset_done.html'}),
url(r'^reset-password/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
password_reset_confirm, {'template_name': 'accounts/password_reset_confirm.html'}),
url(r'^reset-password/complete/$', password_reset_complete, {'template_name': 'accounts/password_reset_complete.html'})
]
NOTE: If I replace password_reset_done and all the others after with their proper name='password_reset_done, name='password_reset_confirm', name='password_reset_complete' parameters everything functions properly, but then I'm stuck with the default templates.
here's the urls.py when it functions:
urlpatterns = [
url(r'^$', views.home),
url(r'^login/$', login, {'template_name': 'accounts/login.html'}),
url(r'^logout/$', logout, {'template_name': 'accounts/logout.html'}),
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, {'template_name': 'accounts/reset_password.html'}),
url(r'^reset-password/done/$', password_reset_done, name='password_reset_done'),
url(r'^reset-password/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
password_reset_confirm, name='password_reset_confirm'),
url(r'^reset-password/complete/$', password_reset_complete, name='password_reset_complete')
]
Only the first template can be changed without causing any errors. I'm still relatively new to django and I didn't find anything in the documentation that helped me solve this problem.
I'll leave other potentially important code below
from settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
Any insight is greatly appreciated.
Upvotes: 0
Views: 1889
Reputation: 557
The approved answer didn't work for me. This did:
views.py:
from django.contrib.auth.views import PasswordResetConfirmView
# ...
class ActivateAccountConfirmView(PasswordResetConfirmView):
template_name = "./registration/account_activate_confirm.html"
urls.py:
re_path(
r'^accounts/activate/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
ActivateAccountConfirmView.as_view(),
name='account_activate_confirm'),
Context: I have a password reset as well as an account activation facility in my application. Also note that this isn't the view the original user asked about, but the same method should work.
Upvotes: 0
Reputation: 600059
You need to add names for those URLs, like you have for your own ones. For example:
url(r'^reset-password/done/$', password_reset_done, {'template_name': 'accounts/password_reset_done.html'}, name='password_reset_done'),
Upvotes: 2