Applying bootstrap styles to django forms -


i want use bootstrap decent website design, unfortunately don't know how style form fields. talking this:

<form class="form-horizontal" method="post" action="."> {% csrf_token %}   {{ form.title.label }}   {{ form.title }} </form> 

how 1 supposed design this?? tried this:

<form class="form-horizontal" method="post" action="."> {% csrf_token %}   <div class="form-control">     {{ form.title.label }}     {{ form.title }}   </div> </form> 

this didn't gave me wanted results.

how can apply bootstrap styles django forms?

if prefer not use 3rd party tools need add attributes classes, prefer having base class model forms inherit from

class bootstrapmodelform(modelform):     def __init__(self, *args, **kwargs):         super(bootstrapmodelform, self).__init__(*args, **kwargs)         field in iter(self.fields):             self.fields[field].widget.attrs.update({                 'class': 'form-control'             }) 

can adjusted... see field widgets form-control css class applied

you can extend specific fields if wish, here's example of inherited form having attribute applied

class myform(bootstrapmodelform):     def __init__(self, *args, **kwargs):         super(myform, self).__init__(*args, **kwargs)         self.fields['name'].widget.attrs.update({'placeholder': 'enter name'}) 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -