zoukankan      html  css  js  c++  java
  • jinja语法

    <!--base.html-->
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <!--html中的包含关系-->
        {% block head %}
            {% include ['includes/_head.html', 'include/_metas.html'] %}
        {% endblock head %}
    </head>
    <body>
    
        <!--页头-->
        <header>{% block header %}{% endblock header %}</header>
    
        <!--block作用域问题,内层block调用外面的item-->
        {% for item in items %}
            <li>{% block loop_item scoped %}{{ item }}{% endblock loop_item %}</li>
        {% endfor %}
    
        <!--页体-->
        <div>{% block content %}{% endblock content %}</div>
    
        <!--页脚-->
        <footer>
            {% block footer %}
                Copyright 2018 by <a href="www.baidu.com">Baidu</a>
            {% endblock footer %}
        </footer>
    
    </body>
    </html>
    
    
    <!--index.html-->
    
    <!--继承父页面-->
    {% extends 'base.html' %}
    
    <!--宏-->
    {% macro input(name, value='', type='text', size=20) %}
        <input type="{{ type }}" name="{{ name }}" value="{{ value }}" size="{{ size }}"/>
    {% endmacro %}
    
    <!--宏引入-->
    {% import '_marcos.html' as ui %}
    
    <!--title-->
    {% block title %}{{ title }}{% endblock title %}
    
    <!--content-->
    {% block content %}
    {% set links=[
        ("home", url_for(".index")),
        ("about", url_for(".about")),
        ("service", url_for(".service")),
        ("project", url_for(".project")),
        ] %}
    
    <nav>
        {% for label, href in links %}
            {% if not loop.first %} | {% endif %}
            <a href="{{ href }}">{{ label }}</a>
        {% endfor %}
    </nav>
    
        <!--重复使用变量-->
        <h1>{{ self.title() }}</h1>
        {{ input('username') }}
        {{ input('password', type='password') }}
    
    {% endblock content %}
    
    
    <!--footer-->
    {% block footer %}
        <hr>
        <!--改写父类方法,且不覆盖父类-->
        {{ super() }}
    {% endblock footer %}
  • 相关阅读:
    微软面试100 题题解
    二元查找树转变成排序的双向链表(树)
    筆試
    PE注入
    内核网络通信
    哈哈哈
    OpenCV 学习
    第一次研究VM程序中的爆破点笔记
    SE2.3.4各试用限制调试笔记
    破解相关书籍
  • 原文地址:https://www.cnblogs.com/themost/p/9027534.html
Copyright © 2011-2022 走看看