You will want to use FieldList
to let WTForms know there can be more than one entry:
field = DecimalField(default=0.0, validators=[NumberRange(min=0, max=2)])
class AForm(Form):
ff = FieldList(field)
Then you should be able to simply set the data in the form constructor:
@app.route('/test', methods=['GET', 'POST'])
def get_form():
entries=[0, 1]
form = AForm(request.form, ff=entries)
ff_l = form.ff.data
if request.method == 'POST' and form.validate():
result = sum(ff_l)
return render_template('res.html', b=result)
return render_template('test.html', form=form)
And your template should now loop over the subfields in form.ff
:
<form action="/test" method=post>
{% for field in form.ff %}
{{ render_field(field) }}
{% endfor %}
<input class="button" type="submit" value="calc">
</form>