Define css class in django Forms

前端 未结 13 691
南旧
南旧 2020-11-27 10:11

Assume I have a form

class SampleClass(forms.Form):
    name = forms.CharField(max_length=30)
    age = forms.IntegerField()
    django_hacker = forms.Boolea         


        
相关标签:
13条回答
  • 2020-11-27 10:46

    Here is another solution for adding class definitions to the widgets after declaring the fields in the class.

    def __init__(self, *args, **kwargs):
        super(SampleClass, self).__init__(*args, **kwargs)
        self.fields['name'].widget.attrs['class'] = 'my_class'
    
    0 讨论(0)
提交回复
热议问题