Reputation: 1250
I am implementing Password reset by using django Rest Auth, two thing I requires when request hits from reactjs frontend I want the email to be customize I want to use password_reset_email.html template.Firstly I used simple PasswordResetView and I got the email but it sends me to native Rest UI PasswordConfirmView.
I want,when User hit request it should use my templates which are, password_reset.html,password_reset_confirm.html,password_reset_done.html... which we make in our templates/appname directory my try:
urls.py:
urlpatterns=[
url(
r'^rest-auth/password/reset/$',
PasswordResetView.as_view(),
name='password_reset',
),
url(
r'^rest-auth/password/reset/confirm/'
r'(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
]
authsystem/templates:
password_reset_confirm.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{% if validlink %}
<h3>Change password</h3>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Change password</button>
</form>
{% else %}
<p>
The password reset link was invalid, possibly because it has already been used.
Please request a new password reset.
</p>
{% endif %}
</body>
</html>
I know the above approach is less but I want the direction how can I make it work I don't want to use rest auth built-in UI, when request hits from react side,How can I use templates when the email is sent,when I click on link in email I want to show my template, token and uid should pass from templates,I have all the templates ready but don't know how to use with Django Rest Auth.
Upvotes: 2
Views: 1566
Reputation: 20702
In general, if you want to override templates from a package, make sure you check first the path of template used in the view. E.g. in the rest-auth package (if you didn't install allauth), password reset is handled by the default Django PasswordResetConfirmView
(django.contrib.auth.views), which uses the template 'registration/password_reset_confirm.html', which for some reason resides in django/contrib/admin/templates/registration.
So the way templates are loaded, if in any of your apps, you have this template, it'll be loaded before the one from Django. Just create authsystem/templates/registration/password_reset_confirm.html and that's the one that will be used instead of the default one inside django/contrib/admin.
If you're using allauth, then the view is PasswordResetFromKeyView
(allauth.account.views) and the corresponding template account/password_reset_from_key.html. Therefore, creating this template in authsystem/templates/account/password_reset_from_key.html will override the one from allauth.
Upvotes: 3