Skip to main content

AdminURLFieldWidget

This class provides a specialized URL input widget designed for use within the administrative interface. It extends the standard URL input functionality by validating the current value and providing additional context for rendering functional links and localized labels in the admin template. The widget automatically applies specific CSS classes and handles URL quoting for safe display.

Attributes

AttributeTypeDescription
template_namestring = "admin/widgets/url.html"The path to the HTML template used to render the URL input widget in the Django admin interface.

Constructor

Signature

def AdminURLFieldWidget(
attrs: dict = None,
validator_class: class = URLValidator
) - > null

Parameters

NameTypeDescription
attrsdict = NoneA dictionary containing HTML attributes to be set on the rendered widget.
validator_classclass = URLValidatorThe class used to instantiate the URL validator for the widget.

Signature

def AdminURLFieldWidget(
attrs: dict = None,
validator_class: class = URLValidator
) - > null

Parameters

NameTypeDescription
attrsdict = NoneA dictionary of HTML attributes to be added to the rendered widget element.
validator_classclass = URLValidatorThe validation class used to verify if the current input value is a properly formatted URL.

Methods


get_context()

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

Builds the template context for rendering the widget, including localized labels and a validated URL for the hyperlink reference.

Parameters

NameTypeDescription
namestrThe name of the form field associated with this widget.
valueanyThe current value of the field to be displayed or validated.
attrsdictAdditional HTML attributes to include in the widget context.

Returns

TypeDescription
dictA dictionary containing the widget state, localized labels for 'Currently' and 'Change', and the quoted URL if valid.