I'm trying to dynamically create a web form with checkboxes and populate a list with the user selections. For example if the user were to select test1 and test2 from the form, I would expect to have a list in python of ['test1', 'test2'].
I am using Flask w/ Jinja2 and Python. However, when I submit the form, I receive a 400 Message (Bad Request).
Here is the relevant Python Code.
from flask import Flask, render_template, request, redirect
CASES = ['test1', 'test2', 'test3', 'test4']
@app.route("/")
def template_test():
return render_template('template.html', title="Home")
@app.route("/TestCases")
def TestCases():
return render_template('testcases.html', cases=CASES, title="Test Cases")
@app.route("/info", methods=['POST'])
def getinfo():
if request.method == 'POST':
test = request.form['checks']
print test
return redirect('/')
else:
return redirect('/')
Here is the relevant html code from the template (testcases.html).
<form action="info" method="post" name="checks">
{% for c in cases %}
<input type="checkbox" name={{c}} value='checks'> {{c}}<br>
{% endfor %}
<br>
<input type="submit" value="Submit">
I am not new to python, but this is my first foray using Flask and Jinja2.