自定义视图组件
comment = forms.CharField(label='备注', widget=forms.TextInput)
自定义样式
comment = forms.CharField(label='备注', widget=forms.TextInput({'class':'comment-class', 'name':'m-comment', 'id':'m-comment'}))
也可以这样
comment = forms.CharField(label='备注', widget=forms.TextInput)
comment.widget.attrs.update({
'class':'comment-class',
})
还可以这样
class MyForm(form.Forms):
...
def __init__(slef, *args, **kwargs):
super().__init__(*args, **kwargs)
self.field['comment'].widget.attrs.update(
{'class':'comment-class'}
)