Flask-渲染模板和传参

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

app.route('/')
def index():
	return render_template('index.html',username='Miracle')
	//如果有多个参数为了方便维护就用字典管理关键字参数,然后进行打散
	content={'username':'Miracle',
			'age'=18}
	return render_template('index.html',**content)
	
if __name__=='main':
	app.run(debug=True)

下面是index.Html

<body>
	<p>用户名:{{username}}</p>
	<p>年龄:{{ age }}</p>
</body>

猜你喜欢

转载自blog.csdn.net/qq_42991834/article/details/89498794