Skip to main content

PasswordResetView

This class provides a form-based view for initiating the password reset process by sending a recovery email to the user. It manages the configuration for email templates, subject lines, and token generation while utilizing a specialized form to validate user input and trigger the reset logic. Upon successful form submission, the view redirects users to a confirmation URL.

Attributes

AttributeTypeDescription
email_template_namestring = "registration/password_reset_email.html"The path to the template used for generating the body of the password reset email sent to the user.
extra_email_contextdictA dictionary of additional context variables to be passed to the email templates during the password reset process.
form_classclass = PasswordResetFormThe form class used to collect the user's email address for the password reset request.
from_emailstringThe email address used as the sender for the password reset email; if None, the DEFAULT_FROM_EMAIL setting is used.
html_email_template_namestringThe path to an optional HTML template used to generate a multipart HTML version of the password reset email.
subject_template_namestring = "registration/password_reset_subject.txt"The path to the template used for generating the subject line of the password reset email.
success_urlstring = reverse_lazy("password_reset_done")The URL to redirect to after the password reset request form has been successfully submitted.
template_namestring = "registration/password_reset_form.html"The path to the template used to render the password reset request form page.
titlestring = _("Password reset")The localized title string displayed on the password reset form page.
token_generatorobject = default_token_generatorThe instance used to generate and verify the unique security tokens included in the password reset links.

Methods


form_valid()

@classmethod
def form_valid(
form: [PasswordResetForm](../forms/passwordresetform.md?sid=django_contrib_auth_forms_passwordresetform)
) - > [HttpResponse](../../../http/response/httpresponse.md?sid=django_http_response_httpresponse)

Triggers the password reset email delivery by saving the form with the configured email templates and security settings before redirecting to the success URL.

Parameters

NameTypeDescription
form[PasswordResetForm](../forms/passwordresetform.md?sid=django_contrib_auth_forms_passwordresetform)The validated form instance containing the user's email address and logic for generating reset links.

Returns

TypeDescription
[HttpResponse](../../../http/response/httpresponse.md?sid=django_http_response_httpresponse)An HTTP redirect response to the success_url defined in the view.