Created
March 2, 2014 11:46
-
-
Save danielthiel/9305415 to your computer and use it in GitHub Desktop.
Mutliple forms in flask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- put Forms here --> | |
<input type="submit" name="button" value="Save"> | |
<input type="submit" name="button" value="Cancel"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: http://flask.pocoo.org/mailinglist/archive/2010/9/12/flask-wtf-multiple-form-per-view/#d8cfeff63b89d028919d4617ed642d15 | |
form1 = FormA(prefix="form1") | |
form2 = FormB(prefix="form2") | |
form3 = FormC(prefix="form3") | |
""" | |
Then, add a hidden field (or just check a submit field): | |
The prefix arg will ensure that each form has unique field names - so | |
form1's submit will be called "form1_submit". | |
""" | |
if request.form['button'] == 'Save': | |
if form1.validate_on_submit() and form1.submit.data: | |
do_save_form_1() | |
else: | |
do_cancel() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment