Created
February 11, 2016 21:15
-
-
Save doobeh/03da3cdcda54ccd85c85 to your computer and use it in GitHub Desktop.
FormField/FieldList Example
This file contains 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
from flask_wtf import Form | |
from wtforms import FormField, FieldList, DecimalField | |
from flask import Flask, render_template | |
app = Flask(__name__) | |
app.secret_key = 'SHG' | |
class PairForm(Form): | |
first = DecimalField('First') | |
second = DecimalField('Second') | |
class EntryForm(Form): | |
pairing = FieldList(FormField(PairForm, 'Pair'), min_entries=2, max_entries=10) | |
@app.route('/', methods=['post','get']) | |
def home(): | |
form = EntryForm() | |
if form.validate_on_submit(): | |
print form.pairing.data | |
return render_template('pair.html', form=form) | |
if __name__ == '__main__': | |
app.run(debug=True, port=5001) |
This file contains 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
<form action="" method="post"> | |
{{ form.hidden_tag() }} | |
{{ form.pairing() }} | |
<input type="submit"/> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment