14👍
New in Django 1.7 is Form.add_error( field, message )
.
https://docs.djangoproject.com/en/dev/ref/forms/api/#django.forms.Form.add_error
8👍
Maybe this will help you . Its generally preferred you override clean and inside the function you could do the following
If you want to raise form specific errors you could do .
self._errors["field"] = ErrorList([u"Error"])
this is make sure you get the error class
if you have an non field error you could simple raise a validation error like so
raise forms.ValidationError(_("Error"))
Hope this helps.
- DataTables: Custom Response Handling
- Django: Possible to load fixtures with date fields based on the current date?
- Testing a session variable
- Django test client does not log in
6👍
- Standard way is
raise ValidationError(message)
. - Move field-specific validation to
clean_<fieldname>()
methods,clean_address
in your case.ValidationError
raised in such method will attach error message to specific field. One raised fromclean()
will be attributed to model in general.
Source:stackexchange.com