如何在django中更改子模板中基本模板的背景

时间:2016-01-02 07:39:24

标签: html django

所以我想要的是更改应用于某些元素的css,这些元素不属于Base.html中任何块的一部分,以便能够在子模板中进行更改。我该怎么做?

base.html文件:

<html>
    <head></head>
    <body background='img.jpg'>{% block content %}Hello world{% endblock %}</body>
</html>

child.html:

{% extends 'Base.html' %}
<!-- Here i want to change the background that was applied to the body in Base.html -->

1 个答案:

答案 0 :(得分:6)

<html>
<head></head>
<body {% block bg %}background='img.jpg' class="base_bg_class"{% endblock %}>{% block content %}Hello world{% endblock %}    </body>
</html>

in child html

{% extends 'base.html' %}

{% block bg %}
  background="child_background.jpg" class="child_bg_class"
{% endblock %}

{% block content %}....{% endblock %}