In fact you can do this in two different ways in two different level:
- You can do this at the level of the form validation:
class NewsletterForm(forms.ModelForm):
email = forms.EmailField(
widget=forms.EmailInput(attrs={
'autocomplete': 'off',
'class': 'form-control',
'placeholder': _('seuemail@email.com'),
'required': 'required'
}),
error_messages={'invalid': 'your custom error message'}
)
class Meta:
model = Newsletter
fields = ['email', ]
- the second way at the level of the model:
2.1. you can do the same as in the form:
email = models.EmailField(error_messages={'invalid':"you custom error message"})
2.2. or you use django built-in Validators:
from django.core.validators import EmailValidator
email = models.EmailField(validators=[EmailValidator(message="your custom message")]) # in you model class
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…