Reputation: 2382
I want to display initial values of form fields in a template.
class MyForm(forms.Form):
myfield = forms.CharField(max_length=100, initial='test')
When I call a specific field everything is fine, but when I loop over form, nothing happens.
{% for field in form.fields %}
{{ field.initial }} # output: (nothing)
{% endfor %}
{{ form.fields.myfield.initial }} # output: 'test'
Is it expected behaviour? How can I access initial values in a loop?
Upvotes: 1
Views: 1835
Reputation: 844
This should work :
{% for field in form %}
{{ field.field.initial }}
{% endfor %}
Upvotes: 1