@register.filter
def add_bootstrap_class(field):
 if (not isinstance(field.field.widget, (django.forms.widgets.CheckboxInput, django.forms.widgets.CheckboxSelectMultiple, django.forms.widgets.RadioSelect, django.forms.widgets.FileInput, str))):
  field_classes = set(field.field.widget.attrs.get('class', '').split())
  field_classes.add('form-control')
  field.field.widget.attrs['class'] = ' '.join(field_classes)
 return field

@ register . filter def add_bootstrap_class ( field ) : if ( not isinstance ( field . field . widget , ( django . forms . widgets . CheckboxInput , django . forms . widgets . CheckboxSelectMultiple , django . forms . widgets . RadioSelect , django . forms . widgets . FileInput , str ) ) ) : field_classes = set ( field . field . widget . attrs . get ( 'class' , '' ) . split ( ) ) field_classes . add ( 'form-control' ) field . field . widget . attrs [ 'class' ] = ' ' . join ( field_classes ) return field
add a "form-control" css class to the fields widget .