• flask jinja2 语法——变量、控制结构及模板继承


    ##   jinja.py

    <!DOCTYPE html>
    <html lang="en">
    <head>
    {% block head %}
    <meta charset="UTF-8">
    <title>Welcome</title>
    {% endblock %}
    </head>
    <body>
    <header>{% block header %}{% endblock %}</header>
    <div>{% block content %}{% endblock %}</div>

    {#{% for item in items %}#}
    {# <li>{% block loop_item scoped %}{{ item }}{% endblock %}</li>#}
    {#{% endfor %}#}
    <footer>
    {% block footer %}
    Copyright 2018 by <a href="www.baidu.com">baidu</a>
    {% endblock %}
    </footer>
    </body>
    </html>
    -----------------------------------------------------------------------------------------------------------


    ##  index.html

    {#<!DOCTYPE html>#}
    {#<html lang="en">#}
    {#<head>#}
    {# <meta charset="UTF-8">#}
    {# <title>welcome</title>#}
    {#</head>#}
    {# <body>
    {#{{ title|safe }}#}
    {#</body> #}
    {% extends 'base.html' %}
    {% import '_macros.html' as ui %}
    {#{% macro input(name, value='', type='text', size=20) %}#}
    {# <input type="{{ type }}"#}
    {# name="{{ name }}"#}
    {# value="{{ value }}"#}
    {# size="{{ size }}"#}
    {# />#}
    {#{% endmacro %}#}
    {% block title %}{{ title }}{% endblock %}
    {% block content %}
    {% set links=[
    {'label':'index', 'href':url_for('.index')},
    {'label':'about', 'href':url_for('.about')},
    {'label':'login', 'href':url_for('.login')},
    ] %}
    <nav>
    {% for link in links %}
    {# {% if loop.index is odd %} | {% endif %}#}
    {% if not loop.first %} | {% endif %}
    <a href="{{ link.href }}">{{ link.label }}</a>
    {% endfor %}
    </nav>
    <h1>{{ self.title() }}</h1>

    {{ ui.input('username') }}
    {{ ui.input('password', type='password') }}
    {% endblock content %}
    {% block footer %}
    <hr>
    {{ super() }}
    {% endblock %}

    {#</html>#}

    --------------------------------------------------------------------------
    ##  base.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
    {% block head %}
    <meta charset="UTF-8">
    <title>Welcome</title>
    {% endblock %}
    </head>
    <body>
    <header>{% block header %}{% endblock %}</header>
    <div>{% block content %}{% endblock %}</div>

    {#{% for item in items %}#}
    {# <li>{% block loop_item scoped %}{{ item }}{% endblock %}</li>#}
    {#{% endfor %}#}
    <footer>
    {% block footer %}
    Copyright 2018 by <a href="www.baidu.com">baidu</a>
    {% endblock %}
    </footer>
    </body>
    </html>
    ---------------------------------------------------------------------------------
    _macros.html
    {% macro input(name, value='', type='text', size=20) %}
    <input type="{{ type }}"
    name="{{ name }}"
    value="{{ value }}"
    size="{{ size }}"
    />
    {% endmacro %}



  • 相关阅读:
    【javaFX学习】(二) 面板手册
    Android开发从系统图库中选择一张图片的方法
    用Android studio进行 OpenCV 开发的第一个项目
    【Android学习入门】Android中activity的启动模式
    Android Studio快捷键【Android学习入门】
    【Android学习入门】Android studio基本设置
    安装Android模拟器Genymotion【Android学习入门】
    Android studio 安装与配置【Android学习入门】
    【知乎】日常生活中有哪些十分钟就能学会并可以终生受用的技能?(一)
    C++学生信息处理
  • 原文地址:https://www.cnblogs.com/pontoon/p/8598649.html
Copyright © 2020-2023  润新知