我有一个动态创建的Charfields列表,但我无法弄清楚如何渲染实际输入(在本例中是textarea)。
这是(简化)循环:
{% for field in form.implementation_fields %}
<label class="col-sm-2 col-form-label">
{{ field.label }}
</label>
<div class="col-sm-10">
{{ field }}
</div>
{% endfor %}
{{field.label}}工作正常,但{{field}}只打印:django.forms.fields.CharField对象位于0x104e7fb50
编辑:这是字段的创建方式
for index, implementation_field in enumerate(ImplementationField.objects.filter(report=report)):
label = "Genomförning %s" % (index + 1)
field = CharField(widget=Textarea(),
label=label, initial=implementation_field.value, required=False)
field.widget.attrs.update({'class': 'form-control implementation_field'})
field_name = "implementation_value_" + str(index)
self.implementation_fields.append(field)
self.fields[field_name] = field