Does this page : 
https://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs
 helps you ?

n [1]: from django import forms

In [2]: class CommentForm(forms.Form):
   ...:         name = forms.CharField(
   ...:                 widget=forms.TextInput(attrs={'class':'special'}))
   ...: 

In [3]: MyForm = CommentForm()

In [4]: MyForm.as_p()
Out[4]: u'<p><label for="id_name">Name:</label> <input id="id_name" type="text" 
class="special" name="name" /></p>'

Dave

On Fri, 16 Sep 2011 02:41:24 -0700 (PDT)
"Kevin.X" <kevin.xia...@gmail.com> wrote:

> Hi, folks
> Is there any simple way to customize a form filed's style? I want to
> add CSS class to a filed according to it's type. Say, <input
> type="text"> should have a class named 'text',  <select> tag should
> have a class 'select', and so on. The way I want to try is that added
> class attribute to widget according to widget's class name when
> initial a form. Is that a good way for my purpose? I really do not
> want to write html forms for so many Models, and I cannot use selector
> like input[type...], cause I need to support IE6.
> Thanks
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to