Friday 15 January 2010

Overloading error messages in Django forms -


Hello, I'm trying to give some custom error messages in my demo form. Can I find the key to load every default error message anywhere?

For example, here's my email form

  email = forms.EmailField (min_length = 6, max_length = 60, error_messages = {'required': 'please all 'Fill in fields', 'invalid': 'Please enter a valid email format', 'invalid_length': 'Email must be between 6 and 60 characters' 'Required' and 'Invalid' overload successfully error code with message and other I do not know any other key for errors (I guess for that third only)).  

I think the default error message for length is "Make sure that this value has at least 6 letters (there is 5)."

It would be great if someone knows the right key, but it would be good to know where to find these keys, so I can also load other errors.

Thank you!

They depend on the field and the area of ​​the area that applies the area. What you can see You can expect that if you search for "default_ar_message" then fields.py :

in the DJjango source , Applies CharField and if you want to override the messages in those errors (if they are extended), then you can add it to your error_messages :

  error_messages: {'Min_length': '...', 'max_length': '...',}    

No comments:

Post a Comment