Styling widgets with django.forms

83 views
Skip to first unread message

playfire

unread,
Dec 8, 2009, 4:28:22 AM12/8/09
to Django users
I am using django.forms for my forms and I want to style my <input>
tags using css. I know I can customize the form template, but how do i
customize the widget itself? Normally I would do <input id="blaaa">
and then put the style in my css file but all I have is
{{ form.fieldname }} to create the widget.

Daniel Roseman

unread,
Dec 8, 2009, 9:30:56 AM12/8/09
to Django users
Well, the input automatically gets an id which is the name of the
field prefixed by 'id_', so you can use that, or you can add a class
value when you declare the field:

def MyForm(forms.Form):
myfield = forms.CharField(widget=forms.TextInput(attrs=
{'class':'myclass'}))

--
DR.
Reply all
Reply to author
Forward
0 new messages