flask用的是jinja2模板,有自己特定的语法
形参:
在html里面留占位参数: {{ 参数名 }},后端传值时,参数名=参数值
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>b页面</title>
</head>
<body>
<h1>{{ user }},你好</h1>
</body>
</html>
# coding:utf-8
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/b/")
def b():
name = 'tom'
return render_template("b.html", user=name)
if __name__ == '__main__':
app.run(debug=True)
声明语句,如声明变量age的值为25:{% set age = 25 %},然后用{{ age }}调用
{% set age = 25%}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>b页面</title>
</head>
<body>
<h1>{{ user }},你好</h1>
<h2>{{ age }}岁</h2>
</body>
</html>
注释
<!--html注释-->
{# jinja2注释python代码 #}
for循环
{% for语句 %}
代码逻辑
{% endfor %}