diff options
| author | Claude Paroz <claude@2xlibre.net> | 2022-01-22 17:21:57 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-10 08:48:27 +0100 |
| commit | 4c76ffc2d6c77c850b4bef8d9acc197d11c47937 (patch) | |
| tree | 943f449e397f362057c3f57906e7bdcc49fcbb2f /docs | |
| parent | cda81b79f212e0666782393c52ad19c2790c9446 (diff) | |
Fixed #29490 -- Added support for object-based Media CSS and JS paths.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/4.1.txt | 5 | ||||
| -rw-r--r-- | docs/topics/forms/media.txt | 27 |
2 files changed, 31 insertions, 1 deletions
diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index 02d51ed2a5..4b62cf09cf 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -192,6 +192,11 @@ Forms * The new ``edit_only`` argument for :func:`.modelformset_factory` and :func:`.inlineformset_factory` allows preventing new objects creation. +* The ``js`` and ``css`` class attributes of :doc:`Media </topics/forms/media>` + now allow using hashable objects, not only path strings, as long as those + objects implement the ``__html__()`` method (typically when decorated with + the :func:`~django.utils.html.html_safe` decorator). + Generic Views ~~~~~~~~~~~~~ diff --git a/docs/topics/forms/media.txt b/docs/topics/forms/media.txt index 6ca7c66fde..7e5a04e3d9 100644 --- a/docs/topics/forms/media.txt +++ b/docs/topics/forms/media.txt @@ -206,7 +206,10 @@ return values for dynamic ``media`` properties. Paths in asset definitions ========================== -Paths used to specify assets can be either relative or absolute. If a +Paths as strings +---------------- + +String paths used to specify assets can be either relative or absolute. If a path starts with ``/``, ``http://`` or ``https://``, it will be interpreted as an absolute path, and left as-is. All other paths will be prepended with the value of the appropriate prefix. If the @@ -254,6 +257,28 @@ Or if :mod:`~django.contrib.staticfiles` is configured using the <script src="https://static.example.com/animations.27e20196a850.js"></script> <script src="http://othersite.com/actions.js"></script> +Paths as objects +---------------- + +.. versionadded:: 4.1 + +Asset paths may also be given as hashable objects implementing an +``__html__()`` method. The ``__html__()`` method is typically added using the +:func:`~django.utils.html.html_safe` decorator. The object is responsible for +outputting the complete HTML ``<script>`` or ``<link>`` tag content:: + + >>> from django import forms + >>> from django.utils.html import html_safe + >>> + >>> @html_safe + >>> class JSPath: + ... def __str__(self): + ... return '<script src="https://example.org/asset.js" rel="stylesheet">' + + >>> class SomeWidget(forms.TextInput): + ... class Media: + ... js = (JSPath(),) + ``Media`` objects ================= |
