I'm using Flask (vsn 0.8) and Flask-WTF (vsn 0.5.2) (e.g., to parse forms) to make a pretty simple website. However, I'm unable to get Flask-WTF to properly parse my GET results.
My relevant code looks like this:
@app.route("/result", methods=("GET", "POST"))
def submit():
form = MyForm()
print request.args
print request.args.get('aws_id', None, type=str)
print form.is_submitted()
if form.validate_on_submit():
flash('Success')
aws_id = form.aws_id.data
return render_template("index.html", form=form)
If I submit my form with a single field called 'aws_id' with GET I get the following output on the console.
127.0.0.1 - - [19/Oct/2011 22:28:59] "GET /result?aws_id=test_string HTTP/1.1" 200 -
ImmutableMultiDict([('aws_id', u'test_string')])
test_string
False
It looks to me like the submit is working correctly, but Flask-WTF isn't doing its thing. Essentially, the old way of dealing with form output works, the request.args.get method, but the new form.is_submitted and form.validate_on_submit aren't doing their magic goodness.
Any ideas? (WTF!)
I moved my app to the root of my site, deleted the one that was there (=redundant), and added request.form
to the MyForm class. That seems to fix it. It was also necessary to set csrf_enabled
to false.
@app.route("/", methods=("GET", "POST"))
def submit():
form = MyForm(request.form, csrf_enabled=False)
if form.validate_on_submit():
print form.data
return render_template("index.html", form=form)