Password Reset with PasswordResetView
A snippet for adding password reset via email using PasswordResetView.
# urls.py
from django.urls import path
from django.contrib.auth.views import PasswordResetView
from django.urls import reverse_lazy
urlpatterns = [
path('reset-password/', PasswordResetView.as_view(
template_name='reset_password.html',
email_template_name='reset_password_email.html',
success_url=reverse_lazy('password_reset_done')
), name='reset_password'),
]
# templates/reset_password.html
<h2>Reset Your Password</h2>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Send Reset Email</button>
</form>
# templates/reset_password_email.html
Click the link below to reset your password:
{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}
Explanation:
-
PasswordResetViewhandles sending the password reset link to the user's email. - We provide a custom template for both the form and the email message.
- The reset email includes a secure token-based link that takes the user to a confirmation page.
-
reverse_lazyis used for lazy resolution of the redirect URL after form submission.
- Category Authentication & Authorization
- Total Views 1395
- Last Modified 30 October, 2025
- Tags #password reset #auth #views #forms
Previous snippet
Restrict Admin Access by Permission
Next snippet