Python django表单模型中的属性
您好,我有django表单模型,我想为它添加自定义类,但仍然遇到错误: TypeError:init()获得意外的关键字参数“attrs” 我的django代码:Python django表单模型中的属性,python,django,Python,Django,您好,我有django表单模型,我想为它添加自定义类,但仍然遇到错误: TypeError:init()获得意外的关键字参数“attrs” 我的django代码: class ContactForm(forms.ModelForm): class Meta: model = ContactFormModel fields = ('name', 'email', 'phoneNumber', 'message',)
class ContactForm(forms.ModelForm):
class Meta:
model = ContactFormModel
fields = ('name', 'email', 'phoneNumber',
'message',)
widgets = {
'name': CharField(attrs={'class': 'myfieldclass'}),
}
感谢您的帮助。
CharField
不是一个小部件,但是它是
widgets = {
'name': forms.TextInput(attrs={'class': 'myfieldclass'}),
}