I need some way to add a class attribute to the output of the label_tag() method for a forms field.
I see that there is the ability to pass in an attrs dictionary a
A bit too late but came across a similar problem. Hope this helps you.
class MyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['myfield1'].widget.attrs.update(
{'class': 'form-control'})
self.fields['myfield2'].widget.attrs.update(
{'class': 'form-control'})
def as_two_col_layout(self):
return self._html_output(
normal_row='%(label)s %(field)s%(help_text)s',
error_row='%s',
row_ender='