Reputation: 423
I am trying to override the default invalid email error message in Django. As the Django Doc says, the following code should work, but it's not. How can I adjust it?
class BootstrapAuthenticationForm(AuthenticationForm):
forms.Form.error_css_class = 'error'
email = forms.EmailField(max_length=254,
error_messages={'required': 'Please enter a valid email address.',
'invalid': 'Please enter a valid email address.'},
widget=forms.EmailInput({
'required': True,
'class': 'form-control',
'placeholder': 'E-mail address',
}))
And, the error_css_class is not working properly: there is no change at all. What's wrong with this setting?
Thanks in advance.
Upvotes: 0
Views: 1631
Reputation: 852
You can use EmailValidator:
email = forms.EmailField(max_length=254, validators=[EmailValidator(message="Your message")]
Upvotes: 3