注释: {# haha #}

对象引用 : {{data.name}}  或者 {{data['name]}}

控制语句放到{%  %}中

        {% if not has_in_gifts and not has_in_wishes %}
            <div class="col-md-1">
                <a class="btn btn-outline"
                   href="#modal">
                    赠送此书
                </a>
            </div>
        {% elif has_in_wishes %}
            <div class="col-md-3">
                <span class="bg-info">已添加至心愿清单</span>
            </div>
        {% else %}
            <div class="col-md-3">
                <span class="bg-info">已添加至赠送清单</span>
            </div>
        {% endif %}
             {% for message in messages %}
                {% if message %}
                    <div class="alert alert-warning" role="alert">{{ message }}</div>
                {% endif %}
            {% endfor %}

 遍历的对象是一个字典

           {% for key, error in form.errors.items() %}
                <div class="alert alert-warning" role="alert">{{ error }}</div>
            {% endfor %}

 Jinja2 笔记

 获取闪现消息,with是变量作用域的限定

         {% with messages = get_flashed_messages() %}
            {% for message in messages %}
                {% if message %}
                    <div class="alert alert-warning" role="alert">{{ message }}</div>
                {% endif %}
            {% endfor %}
        {% endwith %}

 

相关文章:

  • 2022-01-02
  • 2022-12-23
  • 2021-10-21
  • 2022-01-06
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2021-09-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
  • 2021-12-17
  • 2021-12-16
  • 2021-11-21
相关资源
相似解决方案