Django模板:扩展模板能够更改父页面中的CSS吗? [英] django template: Is extended template able to change css in parent page?

查看:203
本文介绍了Django模板:扩展模板能够更改父页面中的CSS吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个django模板页面,其中一个是 base.html,其中将基本的html标签设置为基本模板。现在,我有了一个页面 child.html对其进行扩展,其中包含类似 {%扩展 base.html%} 的内容。现在,我必须更改此特定页面的< body> 背景色,因此在 child.html的CSS中,我写道:

I have two django template pages, one of them is "base.html", with basic html tags setup as a base template. Now I have a page "child.html" that extends it, with something like {% extends "base.html" %} in it. Now I have to change <body> background color for this particular page, so in the css of "child.html" I wrote:

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

但是身体没有似乎对任何变化都没有反应。我想我一定错过了什么。

But the body doesn't seem to respond to any changes. I think I must have missed something. Please help, thanks.

编辑:
在 child.html中,我只是拥有

In "child.html", I simply have

<link rel="stylesheet" type="text/css" href="/site-media/css/template_conf.css"/>

,我尝试在 template_conf.css ,并且没有其他页面包含 template_conf.css

and I try to change body css in template_conf.css, and there's no other page that includes template_conf.css.

推荐答案

在主模板中:

<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 %}

这将呈现< body class = my_new_body_css_class> ...< / body> ,您必须在链接中定义此类CSS。

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

这篇关于Django模板:扩展模板能够更改父页面中的CSS吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆