flask怎样将html中的参数传给视图函数?

flask怎样将html中的参数传给视图函数


泛舟湖上清波郎朗
浏览 902回答 1
1回答

慕姐8265434

可以向模板(template)传递多个参数或者把全部的本地参数传递给template:1. 传递多个参数给template,直接将参数放在render_template()函数里面,参数间用逗号隔开:@app.route('/')def index():content = '.....'user='Micheal'return render_template('index.html', var1=content, var2=user)template中可以直接使用{{var1}}和{{var2}}直接操作变量。2. 传递全部的本地变量给template,使用**locals():@app.route('/')def index():content = '.....'user='Micheal'return render_template('index.html', **locals())template中可以直接使用{{content}}和{{user}}直接操作变量。
打开App,查看更多内容
随时随地看视频慕课网APP