Skip to main content

PasswordResetForm

This class provides a form for initiating the password reset process by collecting a user's email address. It identifies active users with usable passwords associated with the provided email and generates a unique, one-time use password reset link. The class also handles the rendering and delivery of reset instructions via email using customizable templates.

Attributes

AttributeTypeDescription
emailforms.EmailFieldThe email address used to identify and retrieve active user accounts for password reset delivery, limited to a maximum length of 254 characters.

Methods


send_mail()

@classmethod
def send_mail(
subject_template_name: string,
email_template_name: string,
context: dict,
from_email: string,
to_email: string,
html_email_template_name: string = null
) - > null

Send a django.core.mail.EmailMultiAlternatives to to_email.

Parameters

NameTypeDescription
subject_template_namestringThe path to the template used to render the email subject line.
email_template_namestringThe path to the template used to render the plain-text version of the email body.
contextdictA dictionary of data used to populate the email templates, including user and site information.
from_emailstringThe sender's email address.
to_emailstringThe recipient's email address.
html_email_template_namestring = nullThe path to an optional template used to render an HTML version of the email body.

Returns

TypeDescription
nullReturns nothing; sends an email as a side effect.

get_users()

@classmethod
def get_users(
email: string
) - > generator

Given an email, return matching user(s) who should receive a reset.

Parameters

NameTypeDescription
emailstringThe email address used to look up matching user accounts in the database.

Returns

TypeDescription
generatorA generator yielding active User objects that have usable passwords and matching email addresses.

save()

@classmethod
def save(
domain_override: string = null,
subject_template_name: string = registration/password_reset_subject.txt,
email_template_name: string = registration/password_reset_email.html,
use_https: boolean = false,
token_generator: object = default_token_generator,
from_email: string = null,
request: [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest) = null,
html_email_template_name: string = null,
extra_email_context: dict = null
) - > null

Generate a one-use only link for resetting password and send it to the user.

Parameters

NameTypeDescription
domain_overridestring = nullAn optional string to override the site domain used in the reset link.
subject_template_namestring = registration/password_reset_subject.txtThe template path for the email subject line.
email_template_namestring = registration/password_reset_email.htmlThe template path for the plain-text email body.
use_httpsboolean = falseDetermines whether the reset link protocol should be 'https' or 'http'.
token_generatorobject = default_token_generatorThe generator object used to create the unique password reset token.
from_emailstring = nullThe email address that will appear in the 'From' field of the reset email.
request[HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest) = nullThe current HTTP request, used to determine the site name and domain if not overridden.
html_email_template_namestring = nullThe template path for an optional HTML version of the email body.
extra_email_contextdict = nullAdditional key-value pairs to include in the template rendering context.

Returns

TypeDescription
nullReturns nothing; triggers the email delivery process for all matching users.