I am a beginner in using WTForms and Python. I have got a problem with the aggregation of WTForm in a dict or list, rendering through jinja2. For example :
class CJanuary(Form):
nr = int(12)
netto = DecimalField(u'Salary netto', default = 0, places = 2)
brutto = DecimalField(u'Salary brutto', default = 0, places = 2)
class InputMonthlyForm(Form):
january = FormField(CJanuary)
months = [FormField(CJanuary)]
If I render it as below:
{{form.january.netto}}
In this case everything is ok, I get source:
<input id="january-netto" name="january-netto" type="text" value="0.00">
But if I try render from list:
{{form.months[0].netto}}
in source I get nothing.
Checking what is in the list:
{{form.months[0]}}
I get:
<UnboundField(FormField, (<class 'apps.placowy.forms.InputMonthlyForm.CJanuary'>,), {})>
I have searched the internet but I can not find any solution. Is it maybe not possible to aggregate WTForm in an array?
Try to use FieldList
instead of list:
class CJanuary(Form):
nr = int(12)
netto = DecimalField(u'Salary netto', default = 0, places = 2)
brutto = DecimalField(u'Salary brutto', default = 0, places = 2)
class InputMonthlyForm(Form):
january = FormField(CJanuary)
months = FieldList(FormField(CJanuary))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.