From ce1ad98565d98b7939367b2bcab755c3555ceb42 Mon Sep 17 00:00:00 2001 From: "stefan.ivic" Date: Sat, 8 Jun 2024 15:44:17 +0200 Subject: [PATCH] Fixed #35505 -- Added extrabody block to admin/base.html. --- .../contrib/admin/templates/admin/base.html | 1 + docs/ref/contrib/admin/index.txt | 26 +++++++++++++++++++ docs/releases/5.2.txt | 4 ++- .../templates/admin/base_site.html | 2 ++ tests/admin_views/tests.py | 4 +++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/django/contrib/admin/templates/admin/base.html b/django/contrib/admin/templates/admin/base.html index f01a7ab61ce2..18e3a2a9fce2 100644 --- a/django/contrib/admin/templates/admin/base.html +++ b/django/contrib/admin/templates/admin/base.html @@ -121,5 +121,6 @@ +{% block extrabody %}{% endblock extrabody %} diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 20f2ce758255..504ab62368c2 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -2827,6 +2827,32 @@ linked to the document in ``{% block dark-mode-vars %}``. .. _prefers-color-scheme: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme +.. _extrabody: + +``extrabody`` block +=================== + +.. versionadded:: 5.2 + +You can add custom HTML, JavaScript, or other content to appear just before the +closing ```` tag of templates that extend ``admin/base.html`` by +extending the ``extrabody`` block. For example, if you want an alert to appear +on page load you could add a ``admin/base.html`` template override to your +project: + +.. code-block:: html+django + + {% extends 'admin/base.html' %} + + {% block extrabody %} + {{ block.super }} + + {% endblock extrabody %} + ``AdminSite`` objects ===================== diff --git a/docs/releases/5.2.txt b/docs/releases/5.2.txt index fb2a1d017711..0a0cfb0aef3e 100644 --- a/docs/releases/5.2.txt +++ b/docs/releases/5.2.txt @@ -37,7 +37,9 @@ Minor features :mod:`django.contrib.admin` ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -* ... +* The ``admin/base.html`` template now has a new block + :ref:`extrabody ` for adding custom code before the closing + ```` tag. :mod:`django.contrib.admindocs` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/admin_views/templates/admin/base_site.html b/tests/admin_views/templates/admin/base_site.html index 97145712899f..27158e9e4460 100644 --- a/tests/admin_views/templates/admin/base_site.html +++ b/tests/admin_views/templates/admin/base_site.html @@ -1,3 +1,5 @@ {% extends "admin/base.html" %} {% block bodyclass %}bodyclass_consistency_check{% endblock %} + +{% block extrabody %}extrabody_check{% endblock extrabody %} diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index cb6815e7a85a..763fa44ce866 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -1746,6 +1746,10 @@ def test_extended_bodyclass_template_change_form(self): response = self.client.get(reverse("admin:admin_views_section_add")) self.assertContains(response, "bodyclass_consistency_check ") + def test_extended_extrabody(self): + response = self.client.get(reverse("admin:admin_views_section_add")) + self.assertContains(response, "extrabody_check\n") + def test_change_password_template(self): user = User.objects.get(username="super") response = self.client.get(