Get the type of field in django template -
i using django forms , want use twitter bootstrap's css in html. template looks this:
{% field in form %} <div class="form-group"> {{ field.label_tag }}<!--same thing : <label for="{{field.id_for_label}}"></label> --> <input type="{{field.type}}" class="form-control" id="{{field.auto_id}}" placeholder="email"> </div> {% endfor %}
i can't figure out out type value. {{field.type}}
.
is there way type of input field in django templates?
thanks in advance
update: reason asking question because want able apply bootstrap classes input element. in bootstrap3, use default css input types have add form-control class input element so: <input type="text" class="form-control" id="{{field.auto_id}}" placeholder="">.
if use django's field {{field}}
can't add form-control class. hope clarifies things.
i saw app https://github.com/dyve/django-bootstrap3 looks wanted do. surprises me django doesn't allow accessing form type allow more flexibility.
if want access field type refer this answer.
if want override default type of field, use attrs
parameter when defining widget field.
eg.
field_name = forms.charfield(widget=forms.textarea(attrs={'type': 'custom type'}))
also note can pass key value pair attrs
, used attributes in html tag when form rendered.
Comments
Post a Comment