Django Form Widgets SyntaxError: cannot assign to function call

Django Form Widgets SyntaxError: cannot assign to function call

我正在尝试表单小部件,我在我的 forms.py:

中编写了这个 class
class RawProductForm(forms.Form):
    title       = forms.CharField(label='', widget=forms.TextInput(attrs={"placeholder: "Your title"}))
    description = forms.CharField(
                                required= False, 
                                widget=forms.Textarea(
                                    attrs={
                                        "class": "new-class-name two",
                                        "id": "my-id-for-textarea",
                                        "rows": 100,
                                        "cols": 20
                                    }
                                        )
                                )
    price       = forms.DecimalField(initial=199.99)

但是我遇到了一个我不知道如何解决的错误:

line 16
    title       = forms.CharField(label='', widget=forms.TextInput(attrs={"placeholder: "Your title"}))
                                                                   ^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

这是语法问题。 你在 placeholder.

之后遗漏了一些 "

您的代码应如下所示:

widget=forms.TextInput(attrs={"placeholder": "Your title"})