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 %}
  • 相关阅读:
    线性时间将两个有序链表合成一个有序链表(constant additional space)
    C++定义指针数组
    cmd运行java编译文件
    java的方法
    Java流程控制
    用户交互-Scanner
    Java的注释
    编译型语言和解释性语言
    JDK、JRE和JVM
    MarkDown的简单使用
  • 原文地址:https://www.cnblogs.com/themost/p/9027534.html
Copyright © 2011-2022 走看看