自定义视图组件

    1. comment = forms.CharField(label='备注', widget=forms.TextInput)

    自定义样式

    1. comment = forms.CharField(label='备注', widget=forms.TextInput({'class':'comment-class', 'name':'m-comment', 'id':'m-comment'}))

    也可以这样

    1. comment = forms.CharField(label='备注', widget=forms.TextInput)
    2. comment.widget.attrs.update({
    3. 'class':'comment-class',
    4. })

    还可以这样

    1. class MyForm(form.Forms):
    2. ...
    3. def __init__(slef, *args, **kwargs):
    4. super().__init__(*args, **kwargs)
    5. self.field['comment'].widget.attrs.update(
    6. {'class':'comment-class'}
    7. )