亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

flask怎樣將html中的參數傳給視圖函數

flask怎樣將html中的參數傳給視圖函數

SMILET 2018-10-30 13:13:52
查看完整描述

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}}直接操作變量。

查看完整回答
反對 回復 2018-11-16
  • 1 回答
  • 0 關注
  • 1311 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號