I am trying to print off the checkbox value in Flask when I hit the submit button.
app.py snippet:
@app.route('/test2', methods=['GET', 'POST'])
def test2():
if request.method == "POST":
if request.form['submit'] == 'submit':
print(request.args.get('check'))
return render_template('test.html')
HTML:
<div class="container"><br>
<form role="form" method="post">
<input type="checkbox" name="check" value="test">
<button type="submit" name="submit" value="submit">Submit</button>
</form>
</div>
It returns 'None' when I hit the submit button.
I have also tried request.form.get()
@app.route('/test2', methods=['GET', 'POST'])
def test2():
if request.method == "POST":
if request.form['submit'] == 'submit':
print(request.form.get('check'))
return render_template('test.html')
That also returns 'None'.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…