0

I'm trying to send a custom email template with the reset token. But it keeps sending raw HTML no matter what I do. I have previous experience of doing exactly the same thing without any problem with the Django and Django rest framework. Here's how I did it,

urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('store.urls')),

    path('', include('django.contrib.auth.urls')),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

store/urls.py

...
path('password_reset',
      auth_views.PasswordResetView.as_view(
            template_name='registration/password_reset_form.html',
            html_email_template_name='registration/html_password_reset_email.html',
            email_template_name = 'registration/password_reset_email.html',  
            ),
     name='password_reset'
    ),

folder structure

...
templates
|-- registration
     |-- html_password_reset_email.html 
     |-- password_reset_email.html
     |-- ...  
...

Note:

I tried deleting the password_reset_email.html template after that it sends the default Django email template.

Hoping for any guidance to solve the issue thanks in advance.

Avishka Dambawinna
  • 1,180
  • 1
  • 13
  • 29

1 Answers1

0

Finally days(3) of debugging I found my dumb mistake :(,

I was including all auth urls path('', include('django.contrib.auth.urls')) in my main urls.py file and re defining the auth.urls again in store/urls.py differently so the overriding doesn't happen correctly.

So, instead of,

path('password_reset',     # <<< here
      auth_views.PasswordResetView.as_view(
       ...
      ),
     name='password_reset'
    ),

it should be,

 path('password_reset/',     # <<< here
      auth_views.PasswordResetView.as_view(
            ),
     name='password_reset'
    ),

Not gonna delete the question (^.^') #for_sake_of_dumb_fellows_like_me

Avishka Dambawinna
  • 1,180
  • 1
  • 13
  • 29