1 回答

湖上湖
TA貢獻2003條經驗 獲得超2個贊
可以向模板(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}}直接操作變量。
- 1 回答
- 0 關注
- 1311 瀏覽
添加回答
舉報
0/150
提交
取消