Assume I have a form
class SampleClass(forms.Form): name = forms.CharField(max_length=30) age = forms.IntegerField() django_hacker = forms.Boolea
Here is another solution for adding class definitions to the widgets after declaring the fields in the class.
def __init__(self, *args, **kwargs): super(SampleClass, self).__init__(*args, **kwargs) self.fields['name'].widget.attrs['class'] = 'my_class'