Dj-rest-auth overriding reset password default email template not working
I wanna override the default email that gets sent to the user when he forgets his password here is the implementation:
#urls.py
path('dj-rest-auth/', include('dj_rest_auth.urls')),
path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')),
path("password-reset/confirm/<uidb64>/<token>/",TemplateView.as_view(
template_name="main/password_reset_confirm.html"),name='password_reset_confirm'),
#serializers.py
class CustomPasswordResetSerializer(PasswordResetSerializer):
def get_email_options(self):
return {
'html_email_template_name': 'custom_email_template.html',
}
def validate_email(self, value):
self.reset_form = self.password_reset_form_class(data=self.initial_data)
if not self.reset_form.is_valid():
raise serializers.ValidationError(self.reset_form.errors)
elif not User.objects.filter(email=value).exists():
raise serializers.ValidationError("A user with this email already exists!")
return value
# settings.py
REST_AUTH_SERIALIZERS = {
'USER_DETAILS_SERIALIZER': 'main.serializers.UserSerializer',
'PASSWORD_RESET_SERIALIZER': 'main.serializers.CustomPasswordResetSerializer'
}
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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',
],
},
},
]
I tried the solutions from many stackoverflow questions and github issues none of them was working
Other than overriding the get_email_options method i tried overriding the save method like so:
def save(self):
request = self.context.get('request')
opts = {
'use_https': request.is_secure(),
'from_email': getattr(settings, 'DEFAULT_FROM_EMAIL'),
'html_email_template_name': 'custom_email_template.html',
'request': request,
}
self.reset_form.save(**opts)
and it did not work , i tried putting it under
-templates
-registration
password_reset_email.html
and it still did not work.
note that i have the template in the following location while trying the above solutions:
templates
custom_email_template.html