zoukankan      html  css  js  c++  java
  • django template模板 母板 include导入

     一,使用{% block name %}{% endblock %}定义一个模板,在模板页面中它的内容为空,在各页面用{% block name %}自己的标签内容{% endblock %}调用。

    模板可以有多个,在各继续页面得用{% extends 'master.html' %}标明

    二,{% include 'name.html' %} include导入功能可将事先写好的一些常用的页面标签,经常用的,做成一个模块那个页面用那里调用。

    三,无论是母板或includer的标签,里面的模板语言{{ variable }}都能被调用它的页面所渲染

    例子:

    模板master.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>{% block title %}{% endblock %}</title>
    <style>
        .page-header{
            background-color: darkgray;
            color: aliceblue;
            height:48px;
        }
    </style>
    {% block css %}{% endblock %}
    </head>
    <body>
    <div class="page-header">华为管理后台</div>
    {% block content %}{% endblock %}
    <script type="javascript" src="/static/jquery-3.3.1.js"></script>
    {% block js %}{% endblock %}
    </body>
    </html>
    

    tag.html标签:

    <form>
        <input type="text"/>
        <input type="submit"/>
    </form>

    页面:

    {% extends 'master.html' %}
    
    {% block title %}tmp01{% endblock %}
    {% block css %}
        <style>
            body{
                margin: 0 auto;
            }
        </style>
    {% endblock %}
    {% block content %}
        <div>
            <h1>用户管理:</h1>
            {% include 'tag.html' %}
            {% include 'tag.html' %}
            {% include 'tag.html' %}
        </div>
    {% endblock %}
    

      

      

  • 相关阅读:
    [leetcode-135-Candy]
    [leetcode-151-Reverse Words in a String]
    [leetcode-139-Word Break]
    [leetcode-129-Sum Root to Leaf Numbers]
    [leetcode-143-Reorder List]
    [leetcode-141-Linked List Cycle]
    oracle 环境变量(中文显示乱码)
    Oracle 自增长id
    Spring.net 事件的注入
    Spirng.net 替换任意方法
  • 原文地址:https://www.cnblogs.com/alex-hrg/p/10146096.html
Copyright © 2011-2022 走看看