Jinja2 模板使用

Ref

  • http://jinja.pocoo.org
  • http://jinja.pocoo.org/docs/2.10/

操作符

  • 连接字符串
    ~ : Converts all operands into strings and concatenates them.

{{ "Hello " ~ name ~ “!” }} would return (assuming name is set to ‘John’) Hello John!.

变量

{% block stask %} 
{% set cls = "" %}   {#  a var: cls  #}
{% for task in tasks %}  {# task is dict in python, tasks is a list  #}
    {% if task.status == "success"  %} 
        {% set cls = "success" %}
    {% elif task.status == "fail" %}
        {% set cls = "fail" %}
    {% endif %}
    
          {{ task.name }} 
    
{% endfor %}
{% endblock %}

你可能感兴趣的:(python)