1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Fixed #35505 -- Added extrabody block to admin/base.html.

This commit is contained in:
stefan.ivic 2024-06-08 15:44:17 +02:00 committed by Sarah Boyce
parent a0c44d4e23
commit ce1ad98565
5 changed files with 36 additions and 1 deletions

View File

@ -121,5 +121,6 @@
<symbol viewBox="0 0 24 24" width="1rem" height="1rem" id="icon-sun"><path d="M0 0h24v24H0z" fill="currentColor"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol>
</svg>
<!-- END SVGs -->
{% block extrabody %}{% endblock extrabody %}
</body>
</html>

View File

@ -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 ``</body>`` 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 }}
<script>
document.addEventListener('DOMContentLoaded', function() {
window.alert('Welcome!');
});
</script>
{% endblock extrabody %}
``AdminSite`` objects
=====================

View File

@ -37,7 +37,9 @@ Minor features
:mod:`django.contrib.admin`
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ...
* The ``admin/base.html`` template now has a new block
:ref:`extrabody <extrabody>` for adding custom code before the closing
``</body>`` tag.
:mod:`django.contrib.admindocs`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -1,3 +1,5 @@
{% extends "admin/base.html" %}
{% block bodyclass %}bodyclass_consistency_check{% endblock %}
{% block extrabody %}extrabody_check{% endblock extrabody %}

View File

@ -1746,6 +1746,10 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase):
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</body>")
def test_change_password_template(self):
user = User.objects.get(username="super")
response = self.client.get(