[Fixed]-Accessing the Input Type from forms in Django

1👍

I think an easier way to do that is by adding the HTML class to the field properties. You can do this by.

field = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))

In that whay, you would only need to do:

<label class="control-label" for="id_{{ field.name }}">{{ field.label }}</label>
{{ field }}

edit: models -> forms

Leave a comment