Skip to main content

ReadOnlyPasswordHashWidget

This class provides a read-only widget for displaying password hash information within a form. It determines whether a password is set or usable to provide an appropriate label for a password management button. The widget uses a specific template to render the hash status and ensures that no label ID is associated with the field.

Attributes

AttributeTypeDescription
template_namestring = auth/widgets/read_only_password_hash.htmlThe path to the HTML template used to render the read-only password hash widget.

Methods


get_context()

@classmethod
def get_context(
name: string,
value: string,
attrs: dict
) - > dict

Prepares the template context for rendering the widget, determining whether to display a 'Reset' or 'Set' password button based on the password's usability.

Parameters

NameTypeDescription
namestringThe name of the form field associated with this widget.
valuestringThe hashed password string used to determine if the password is currently set or unusable.
attrsdictAdditional HTML attributes to be rendered on the widget element.

Returns

TypeDescription
dictA dictionary containing template variables, including the appropriate button label for the password state.

id_for_label()

@classmethod
def id_for_label(
id_: string
) - > null

Returns None to indicate that this read-only widget should not be associated with a clickable label element.

Parameters

NameTypeDescription
id_stringThe HTML ID of the widget element.

Returns

TypeDescription
nullAlways returns None as the widget does not support label focus.