Django模板语言继承

 

母板 html

定义需要继承的块  {% block 模块名字 %}{%endblock%}

 

在html需要继承的位置写块
()重点要写css 与js 继承块)

例如:

  

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{% block title %}{%endblock%}</title>
    <style type="text/css">
    </style>
    {% block css%}{%endblock%}
</head>
<body>
    {% block page_header %}{% endblock %}
    {% block page_content %}{% endblock %}
    {% block page_footer %}{% endblock %}
    <script type="text/javascript"></script>
    {% block js %}{% endblock %}
</body>
</html>

  

 

子板 html

需要在子板顶部 写入要继承模板对象 {%extends '母板的名字'%}

 

要继承块位置写内容 {% block 模块名字 %}自己的页面内容{%endblock%}  

 

 

例如

{% extends 'mother_blank.html' %}

{%block title %}继承的母板样品{%  endblock%}

{% block css %}
    <style>
        #header{ height: 48px; background-color:blue;}
    </style>
{% endblock %}

{% block page_header %}<div id="header">这是页头</div>{% endblock %}

{% block page_content %}<div id="content">这是中心</div>{% endblock %}

  

posted @ 2020-05-22 13:42  JIMfan  阅读(125)  评论(0)    收藏  举报