我試圖從複選框中獲取值的列表。使用燒瓶通過python獲取複選框中的值列表
我發現了一個看起來可以解決我的問題的帖子(How to get if checkbox is checked on flask),但是,我仍在繼續收到此錯誤:錯誤的請求瀏覽器(或代理)發送了此服務器無法理解的請求。
我會發布我的整個代碼塊放在上下文中,但沒有添加複選框,它工作正常。事實上,我有一個下拉菜單相同的選項,它工作正常。
請注意,雖然我在python中的定期編碼,我是一個初學者html和瓶。
<form action='/user_rec' method='POST' id='submitform'>
<input type='text', placeholder='user id' name='user_input'>
<button type="submit" class="btn btn-success">Recommend</button>
<br><br>
<h2>Other Options</h2>
<h5>Best Number of Players</h5>
<div class="checkbox">
<label><input type="checkbox" name="check" value="1">1</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="check" value="2">2</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="check" value="3">3</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="check" value="4">4</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="check" value="5">5+</label>
</div>
<h5>Minimum Play Time (minutes)</h5>
<input type="text", placeholder='0' name='min_time'>
<br><br>
<h5>Maximum Play Time (minutes)</h5>
<input type="text", placeholder='500000' name='max_time'>
</form>
和我的Python代碼:
@app.route('/user_rec', methods=['POST'])
def button1():
user_name = (request.form['user_input'])
best_num_player = (request.form['best_num_player'])
min_time = (request.form['min_time'])
max_time = (request.form['max_time'])
players = request.form.getlist('check')
它可能是你的代碼的其他部分。爲什麼不顯示完整的Python代碼。 –