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
| Attribute | Type | Description |
|---|---|---|
forms.EmailField | The 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
| Name | Type | Description |
|---|---|---|
| subject_template_name | string | The path to the template used to render the email subject line. |
| email_template_name | string | The path to the template used to render the plain-text version of the email body. |
| context | dict | A dictionary of data used to populate the email templates, including user and site information. |
| from_email | string | The sender's email address. |
| to_email | string | The recipient's email address. |
| html_email_template_name | string = null | The path to an optional template used to render an HTML version of the email body. |
Returns
| Type | Description |
|---|---|
null | Returns 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
| Name | Type | Description |
|---|---|---|
string | The email address used to look up matching user accounts in the database. |
Returns
| Type | Description |
|---|---|
generator | A 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
| Name | Type | Description |
|---|---|---|
| domain_override | string = null | An optional string to override the site domain used in the reset link. |
| subject_template_name | string = registration/password_reset_subject.txt | The template path for the email subject line. |
| email_template_name | string = registration/password_reset_email.html | The template path for the plain-text email body. |
| use_https | boolean = false | Determines whether the reset link protocol should be 'https' or 'http'. |
| token_generator | object = default_token_generator | The generator object used to create the unique password reset token. |
| from_email | string = null | The email address that will appear in the 'From' field of the reset email. |
| request | [HttpRequest](../../../http/request/httprequest.md?sid=django_http_request_httprequest) = null | The current HTTP request, used to determine the site name and domain if not overridden. |
| html_email_template_name | string = null | The template path for an optional HTML version of the email body. |
| extra_email_context | dict = null | Additional key-value pairs to include in the template rendering context. |
Returns
| Type | Description |
|---|---|
null | Returns nothing; triggers the email delivery process for all matching users. |