我遇到了只能拥有自定义错误消息或占位符文本的问题。一旦将自定义错误消息添加到 ModelForm 中,占位符文本就不再显示——顺序不会影响结果。提前感谢您的任何帮助和建议!
class LetterForm(ModelForm):
name = forms.CharField()
class Meta:
model = Letter
exclude = ('date_submitted', 'read', 'approved', 'post', 'date_post', 'url', 'tags',)
widgets = {
'youtube': forms.TextInput(attrs={'placeholder': 'youtube'}),
'name': forms.TextInput(attrs={'placeholder': 'name'}),
'location': forms.TextInput(attrs={'placeholder': 'location'}),
'email': forms.TextInput(attrs={'placeholder': 'email'}),
}
name = forms.CharField(error_messages={'required': 'Don\'t want to share your real name?'
' Just enter Anonymous.'})