Reputation: 103
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?
Upvotes: 3
Views: 84
Reputation: 7450
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
Upvotes: 6