mirror of
https://github.com/django/django.git
synced 2025-04-01 12:06:43 +00:00
Fixed #35505 -- Added extrabody block to admin/base.html.
This commit is contained in:
parent
a0c44d4e23
commit
ce1ad98565
@ -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>
|
<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>
|
</svg>
|
||||||
<!-- END SVGs -->
|
<!-- END SVGs -->
|
||||||
|
{% block extrabody %}{% endblock extrabody %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -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
|
.. _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
|
``AdminSite`` objects
|
||||||
=====================
|
=====================
|
||||||
|
|
||||||
|
@ -37,7 +37,9 @@ Minor features
|
|||||||
:mod:`django.contrib.admin`
|
: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`
|
:mod:`django.contrib.admindocs`
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
{% extends "admin/base.html" %}
|
{% extends "admin/base.html" %}
|
||||||
|
|
||||||
{% block bodyclass %}bodyclass_consistency_check{% endblock %}
|
{% block bodyclass %}bodyclass_consistency_check{% endblock %}
|
||||||
|
|
||||||
|
{% block extrabody %}extrabody_check{% endblock extrabody %}
|
||||||
|
@ -1746,6 +1746,10 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase):
|
|||||||
response = self.client.get(reverse("admin:admin_views_section_add"))
|
response = self.client.get(reverse("admin:admin_views_section_add"))
|
||||||
self.assertContains(response, "bodyclass_consistency_check ")
|
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):
|
def test_change_password_template(self):
|
||||||
user = User.objects.get(username="super")
|
user = User.objects.get(username="super")
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user