4

我遇到了只能拥有自定义错误消息或占位符文本的问题。一旦将自定义错误消息添加到 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.'})
4

1 回答 1

3

弄清楚了。我会把这个留给任何可能感兴趣的人

name = forms.CharField(error_messages={'required': 'message'},
                       widget=forms.TextInput(attrs={'placeholder': 'Name'}))
于 2013-04-15T18:43:41.307 回答