python - How to get a list of values with WTForms in Flask? -
python - How to get a list of values with WTForms in Flask? -
in website i'm building flask i'm using wtforms validate submitted forms. in 1 form, i'm submitting list of values form (the hidden fields generated client side using js):
<form action="" method="post" id="prop-form"> <input type="hidden" name="ids[]" value="54511ea9c1a36b4e910ce52a"> <input type="hidden" name="ids[]" value="54511ea9c1a36b4e910ce52d"> <input id="title" name="title" size="30" type="text" value=""> <input type="submit" value="save form"> </form>
on flask side, can contents of ids[]
using next code:
print request.form print request.form.getlist('ids[]')
prints out:
immutablemultidict([('ids[]', u'54511ea9c1a36b4e910ce52a'), ('ids[]', u'54511ea9c1a36b4e910ce52d'), ('title', u'blablabla')]) [u'54511ea9c1a36b4e910ce52a', u'54511ea9c1a36b4e910ce52d']
but when create selectmultiplefield
in wtform follows:
ids = selectmultiplefield('ids[]')
and seek values, empty list:
print form.ids.data # prints out []
any thought how mimic behaviour of request.form.getlist('ids[]')
using wtforms? tips welcome!
python flask wtforms flask-wtforms werkzeug
Comments
Post a Comment