一組表單里有兩個提交按鈕 <input type="submit">:<form action="{{ url_for('index') }}" method="post">
<input type="submit" name="up" value="up">
<input type="submit" name="down" value="down"></form>python 代碼:if request.method == 'POST': if request.form['up']:
return redirect(url_for('index'))
elif request.form['down']:
return redirect(url_for('index'))其中 up 這個可以正常提交,但是 down 這個就報錯:Bad Request The browser(or proxy) sent a request that this server could not understand.怎么解決?
2 回答

炎炎設計
TA貢獻1808條經驗 獲得超4個贊
什么意思,你要做什么?最后的返回不都是一樣的。
而且 request.form[xx] 不是返回的邏輯判斷值吧?
如果沒有在在 form 中沒有找到相應的數值,服務器直接返回當做錯誤請求返回。
你可以這樣,把form改一下,然后直接判斷值。
<form action="{{ url_for('index') }}" method="post"> <input type="submit" name="key" value="up"> <input type="submit" name="key" value="down">

12345678_0001
TA貢獻1802條經驗 獲得超5個贊
這里會出錯的原因是UP這個值在request.form里面沒有的。
用 if "up" in request.form應該可以避免這個問題
添加回答
舉報
0/150
提交
取消