【发布时间】:2017-11-19 21:37:53
【问题描述】:
我正在尝试从复选框中获取值列表。
我找到了一个帖子,可以解决我的问题 (How to get if checkbox is checked on flask),但是,我继续收到此错误:错误请求浏览器(或代理)发送了一个此服务器无法理解的请求。
我将发布我的整个代码块以将其置于上下文中,但没有添加复选框,它可以正常工作。事实上,我有与下拉菜单相同的选项,而且效果很好。
请注意,虽然我经常使用 python 编写代码,但我是 html 和 flask 的初学者。
<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 代码。