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 %}
  • 相关阅读:
    Class Loading Deadlocks
    Find out your Java heap memory size
    ZookeeperGettingStarted
    ZooKeeper的Znode剖析
    nginx+iis实现负载均衡
    ubuntu 18.04下svn的安装与基本命令
    在ubuntu中如何向U盘复制粘贴文件 Read-only file system
    Ubuntu16.04下安装破解secureCRT和secureFX的操作记录
    securecrt8注册码
    Doris FE负载均衡配置
  • 原文地址:https://www.cnblogs.com/themost/p/9027534.html
Copyright © 2011-2022 走看看