Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attributing a specific class to each field of a django-form

I have a form in django and I want to attribute a class to some fields. that's because I want to use those classes in my css code and I don't want all fields have the same style.

for example my form has 2 text fields and a button. I don't want to style the text fields as same as each other. I want the first to be right-to-left and the second to be left-to-right.

we can use required_css_class = 'required' but it's just for the required fields and not for every field I want. Any ideas?

like image 371
Mehran Abbasi Avatar asked Dec 03 '25 12:12

Mehran Abbasi


1 Answers

class CommentForm(forms.Form):
    name = forms.CharField(
                widget=forms.TextInput(attrs={'class':'special'}))
    url = forms.URLField()
    comment = forms.CharField(
               widget=forms.TextInput(attrs={'size':'40'}))

More here

like image 138
rantanplan Avatar answered Dec 06 '25 17:12

rantanplan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!