django template: Is extended template able to change css in parent page?

不羁岁月 提交于 2019-12-03 03:48:48
ablm

In the main template:

<body class="{% block body_class %}{% endblock %}">
...
</body>

Then in the child template, just define the block:

{% block body_class %} my_new_body_css_class {% endblock %}

This will render a <body class="my_new_body_css_class">...</body> and you have to define this class in a linked CSS.

To do this add a block in base.html in the head that allow you to inset another css AFTER the one in base.html

<head>

    .... other head tags ....

    <link rel="stylesheet" type="text/css" href="/site-media/css/template_conf.css"/>
    {% block extra_css %}{% endblock %}
</head>

This allows you to override css tags in template_conf.css by adding in another <link> tag in child.html

{% block extra_css %}
<link rel="stylesheet" type="text/css" href="/site-media/css/child_template.css"/>
{% endblock %}

This allows you to override the partd of base.html that needs to change, while still being able to tweak the parts of the page in child.html that are required.

if you see the new css loaded in the firebug or other browser debugger, please try:

body {
background-color: #000000 !important;
/* some other css here */

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!