12、在模板中定义变量

模板文件 index.html

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<title>Title</title>
	</head>
	<body>
    {# set定义变量 #}
 	   {% set telephone ='1388888888' %}
 	   {% set nav = [('index.html', 'index'),('product.html', 'product')] %}
 	   {{ telephone }}<br />
 	   {{ nav}} <br />

    {# with 定义变量 #}
 	   {% with pass = 60 %}
 		 {{ pass }}
 	   {% endwith %}
	</body>
</html>

定义主程序

from flask import Flask,render_template
app = Flask(__name__)

@app.route('/')
def hello_world():
    return render_template('index.html')
    
if __name__ == '__main__':
    app.run(debug=True)

参考资料

https://weread.qq.com/web/reader/0a932660718ac6bc0a9702e

posted @ 2022-06-01 01:51  tiansz  阅读(35)  评论(0编辑  收藏  举报