Hi Kevin, For this you might want to use something like django-uni-form: http://readthedocs.org/docs/django-uni-form/en/latest/
Regards, Jacco On Fri, Sep 16, 2011 at 1:58 PM, Kevin.X <kevin.xia...@gmail.com> wrote: > Dave, > Thanks for your reply. But I want a more general way to specify the > class of a widget. Is that a little boring when you want a text input > with class 'text', but you have to call forms.CharField with the > widget param every time? > > > On Sep 16, 7:21 pm, Dave <davegar...@gmail.com> wrote: > > Does this page : > https://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms...helpsyou > ? > > > > 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. > > -- 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.