Tuesday, December 11, 2007

Adding classes/style to django form elements

The 'attrs' argument to the Widget class used with each particular
Field (the Widget is what actually renders the HTML) accepts a
dictionary which will become HTML attribute names and values. For
example:

username = forms.CharField(widget=forms.TextInput(attrs={'class': 'myclass'}))

will become:



the old forms default of having class attributes for each
input type (e.g. class=vTextField for type=text)

No comments: