Search code examples
djangoformsmessage

Django override default form error messages


How can I overwrite the default form error messages (for example: need them in other language) for the all apps in my project (or at least for 1 app)

Thanks!


Solution

  • The easiest way is to provide your set of default errors to the form field definition. Form fields can take a named argument for it. For example:

    my_default_errors = {
        'required': 'This field is required',
        'invalid': 'Enter a valid value'
    }
    
    class MyForm(forms.Form):
        some_field = forms.CharField(error_messages=my_default_errors)
        ....