我想在 Django 的表单文本区域中放置一个占位符

I want to place a placeholder in my forms textarea in Django

我想在文本区域的末尾写一个占位符:'*required'。如何为我的字段执行此操作?

forms.py

class CustomerForm2(forms.ModelForm):

    class Meta:
        model = Customer
        fields = (
        'order_id','full_name','company','email',
        'phone_number','note')


        }

您可以在 CustomerForm2 形式中添加以下代码。

class CustomerForm2(forms.ModelForm):
    note= forms.CharField(
        required=True,
        widget=forms.Textarea(
            attrs={"placeholder": "*required",}
        ),
    )

    class Meta:
        ...

希望对您有所帮助。