There is a very easy to install and great tool for Django that I use for styling, and it can be used for all front-end frameworks like Bootstrap, Materialize, Foundation, etc. This is called custom widgets. Documentation: Widget Tweaks
Instead of using the default value:
{{ form.as_p }} or {{ form.as_ul }}
You can style it using the render_field attribute, which gives you a more html style for styling, as in this example:
template.html
{% load widget_tweaks %} <div class="container"> <div class="col-md-6"> {% render_field form.field1 class+="form-control myCSSclass" placeholder="Placeholder for field1" %} </div> <div class="col-md-6"> {% render_field form.field2 class+="myCSSclassX myCSSclass2" placeholder=form.field2.label %} </div> </div>
This makes it easy to store the frontend in the interface and the backend in the backend instead of doing this:
class MyForm(forms.Form): field1 = forms.CharField(widget=forms.TextInput(attrs={'class' : 'myCSSclass'})) field2 = forms.CharField(widget=forms.TextInput(attrs={'class' : 'myCSSclassX myCSSclass2'}))
which, in my opinion, is very limited and easier to get confused
source share