[BangPypers] Mapping django forms to Bootstrap fields

Avneesh Chadha avneesh.chadha at gmail.com
Mon Sep 8 19:38:02 CEST 2014


Hi All,

I am first time django user. I am trying to use django with bootstrap 3
and  can't seem to be able map form fields I create to the bootstrap fields
in the web page.


Things I figured out till now:

1.Write the attributes for the fields as wigdets while declaring the form.

example :

*Name = forms.CharField(widget=forms.TextInput(attrs={'type': 'text','id':
'Name','class': 'form-control','placeholder':'Name'}))*


2.Using Django-bootstrap-form : I tried to use this, but it just renders
the fields using its own CSS . I couldn't figure out how to modify their
appearance by adding classes or attributes using this, also the
documentation is utterly horrible.

Isn't there somthing  in django  which lets me do the following (if my
field is myform.username, then I can map it like) :

<input type="text" for="{{myform.username}}" class="form-control"
id="username" placeholder="Username" >

What is the best(and easiest) way of going about doing this?!

Thanks in advance.


More information about the BangPypers mailing list