0

I am trying to customize the password_reset_form.html and render my own customized form for password reset. But for some reason, it keeps redirecting me to the default django password_reset form. what could i be doing wrong.

root/urls.py
    url('accounts/', include('django.contrib.auth.urls')), 


accounts/urls.py
from django.conf.urls import url
from .views import *
from django.contrib.auth import views as auth_views


urlpatterns  = [
url(r'^password/change/$',
        auth_views.PasswordChangeView.as_view(),
        name='password_change'),
url(r'^password/change/done/$',
        auth_views.PasswordChangeDoneView.as_view(),
        name='password_change_done'),
url(r'^password/reset/$',
        auth_views.PasswordResetView.as_view(),
        name='password_reset'),
url(r'^password/reset/done/$',
        auth_views.PasswordResetDoneView.as_view(),
        name='password_reset_done'),
url(r'^password/reset/\
        (?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(),
        name='password_reset_confirm'),

url(r'^password/reset/complete/$',
        auth_views.PasswordResetCompleteView.as_view(),
        name='password_reset_complete'),
]

template folder templates

Anastacia
  • 33
  • 2
  • 5

1 Answers1

0

I had the same problem and I fixed it by passing arguments to the view.

from django.urls import path, reverse_lazy
from django.contrib.auth import views as auth_views
app_name = 'my_app'

urlpatterns = [

    ...

    path('password_reset/', auth_views.PasswordResetView.as_view(

        template_name='./my_app/password_reset_form.html',
        success_url=reverse_lazy('my_app:password_reset_done'),
        subject_template_name='./my_app/password_reset_subject.txt'),
     name='password_reset'),

    path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),

...
]

For a full list of the arguments you can check the gitlab reference:

https://github.com/django/django/blob/master/django/contrib/auth/views.py

Structure of my project:

  • my_project
    • my_app
      • templates
        • my_app
          • password_reset_subject.txt
          • password_reset_form.html
      • apps.py
      • urls.py
      • views.py
    • my_project
      • settings
      • urls
      • wsgi

...

In my_project/settings also:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

Here the answer that helped me: Django password_reset/done page overriding my custom URL