Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django表单模型中的属性_Python_Django - Fatal编程技术网

Python 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',)

您好,我有django表单模型,我想为它添加自定义类,但仍然遇到错误:

TypeError:init()获得意外的关键字参数“attrs”

我的django代码:

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'}),
}