lundi 24 août 2015

Flask isn't getting the checkbox value

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['test'] == 'test':
            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['test'] == 'test':
            print(request.form.get('check'))

    return render_template('test.html')

That also returns 'None'.




Aucun commentaire:

Enregistrer un commentaire