注释: {# 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 %}
获取闪现消息,with是变量作用域的限定
{% with messages = get_flashed_messages() %} {% for message in messages %} {% if message %} <div class="alert alert-warning" role="alert">{{ message }}</div> {% endif %} {% endfor %} {% endwith %}