Django - form Clean() and field errors

RS7 picture RS7 · Apr 1, 2012 · Viewed 12.7k times · Source

I'm trying to set field errors in a form clean() and I'm currently doing:

self._errors['address'] = self._errors.get('address', ErrorList())
self._errors['address'].append(_(u'Please specify an address.'))

Is there a better and if possible shorter method for doing this?

Answer

ManicDee picture ManicDee · Oct 29, 2014

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