user2307087
user2307087

Reputation: 423

Overriding default error messages in email input widget in django

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

Answers (1)

simopopov
simopopov

Reputation: 852

You can use EmailValidator:

email = forms.EmailField(max_length=254, validators=[EmailValidator(message="Your message")]

Upvotes: 3

Related Questions