「CommentForm.Meta.fields cannot be a string. Did you mean to type: (‘comment’,)?」の解決方法

2022年5月3日

「CommentForm.Meta.fields cannot be a string. Did you mean to type: ('comment',)?」の解決方法

djangoでフォームを作成していたら下記のようなエラーが出ました。


CommentForm.Meta.fields cannot be a string. Did you mean to type: ('comment',)?

正しい「forms.py」は下の通りです。


class CommentForm(ModelForm):
    class Meta:
        model = Comment
        fields = ("comment",)

下記の通り「,」を付ける事で解決しました。


fields = ("comment")   #修正前
fields = ("comment",)  #修正後

YouTube

2022年5月3日