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
| Attribute | Type | Description |
|---|---|---|
| template_name | string = "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
| Name | Type | Description |
|---|---|---|
| attrs | dict = None | A dictionary containing HTML attributes to be set on the rendered widget. |
| validator_class | class = URLValidator | The class used to instantiate the URL validator for the widget. |
Signature
def AdminURLFieldWidget(
attrs: dict = None,
validator_class: class = URLValidator
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| attrs | dict = None | A dictionary of HTML attributes to be added to the rendered widget element. |
| validator_class | class = URLValidator | The 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
| Name | Type | Description |
|---|---|---|
| name | str | The name of the form field associated with this widget. |
| value | any | The current value of the field to be displayed or validated. |
| attrs | dict | Additional HTML attributes to include in the widget context. |
Returns
| Type | Description |
|---|---|
dict | A dictionary containing the widget state, localized labels for 'Currently' and 'Change', and the quoted URL if valid. |