Django: custom ModelForm error message and placeholder

My only problem was that I have either my own error message or placeholder text. As soon as a custom error message is added to ModelForm, the placeholder text is no longer displayed, and the order does not affect the result. Thank you in advance for your help and suggestions!

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
source share
1 answer

Figured it out. I just leave it here for everyone who is interested.

 name = forms.CharField(error_messages={'required': 'message'}, widget=forms.TextInput(attrs={'placeholder': 'Name'})) 
+3
source

All Articles