@library.global_function
def field_with_attrs(bfield, **kwargs):
 if kwargs.get('label', None):
  bfield.label = kwargs['label']
 bfield.field.widget.attrs.update(kwargs)
 return bfield

@ library . global_function def field_with_attrs ( bfield , ** kwargs ) : if kwargs . get ( 'label' , None ) : bfield . label = kwargs [ 'label' ] bfield . field . widget . attrs . update ( kwargs ) return bfield
allows templates to dynamically add html attributes to bound fields from django forms .