Reputation: 1125
I need to do some logic in HTML page depending on field type. For example something to do if input is type="text" or if it is textarea or checkbox....
{% for field in formFields %}
{{field}}
{% endfor %}
When i do something like this: {{field.field}}
i get something like this:
<django.forms.fields.IntegerField object at 0x04812750>
How to use this or is better way?
Upvotes: 0
Views: 65
Reputation: 12931
Specify field type in your views(or forms.py
), do not contain complex logic in your template for field rendering,
class FormClass(ModelForm):
my_field = forms.CharField(widget=forms.Textarea)
Then my_field will be rendered as textarea in template, each field type has its own widget, read the docs here.
Upvotes: 3