Jinja2
简介
python 模板语言
{% block title %}{% endblock %}
- {% for user in users %}
- {{ user.username }}
- {% endfor %}
特性
沙箱中执行
强大的 HTML 自动转义系统保护系统免受 XSS
模板继承
及时编译最优的 python 代码
可选提前编译模板的时间
易于调试。异常的行数直接指向模板中的对应行。
可配置的语法
使用
{% 用于执行语句
{{ 输出语句结果到模板
{{}}中的运算
变量
变量
{{ foo[‘bar’] }}
变量赋值
{% set key, value = call_something() %}
注释
{# note: disabled template because we no longer use this
{% for user in users %}
…
{% endfor %}
#}