From 4c76ffc2d6c77c850b4bef8d9acc197d11c47937 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 22 Jan 2022 17:21:57 +0100 Subject: Fixed #29490 -- Added support for object-based Media CSS and JS paths. --- docs/releases/4.1.txt | 5 +++++ docs/topics/forms/media.txt | 27 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'docs') 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 ` + 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 +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 ``