flask框架使用jinja2模板引擎。简单的说,模板就是一个纯html文件中夹杂着占位符,在渲染模板时用真实变量值替换占位符,就形成了最终的前台页面。
1.模板存放位置:
默认情况下,flask在根目录下的templates文件夹下寻找模板;
2.渲染模板:
render_template('模板名')
3.变量表示:
使用下面形式的占位符表示变量
{{ var }}
4.jinja2支持流程控制,循环,宏,模板继承,所有的语句都要写在以下形式的占位符中:
{% if %}
{% else %}
{% endif %}