Accueil / Blog / Métier / Archives / Remove django form field validation errors manually

Remove django form field validation errors manually

Par Mathieu Leplatre publié 06/12/2011, édité le 11/05/2015

Sometimes I look for something which seems so simple and stupid that I can't imagine it does not exist. It makes me wonder why and who is the fool. Worse, I can't be sure about my search keywords to prove me anything.

I just wanted to delete, reset or remove the validation errors of a single form field, within a django view, without overriding the form or field class.

A one-liner

aform.errors['afield'] = aform['afield'].error_class()

That's it folks !

  • This will not affect other fields errors or non-field errors ;
  • This will reuse nicely the field error class (ErrorDict or ErrorList) ;
  • You cannot set aform.errors['afield'] = None or your form full_clean() will be performed again !
  • Obviously, the ideal approach is to override your form clean() properly.
ABONNEZ-VOUS À LA NEWSLETTER !
Voir aussi
Formation Django initiation à Toulouse du 13 au 15 mars Formation Django initiation à Toulouse du 13 au 15 mars 26/01/2017

Entrez de plain-pied dans l'univers de Django aux côtés de développeurs ayant une expérience de ...

Retour sur la PyConFr 2016 Retour sur la PyConFr 2016 18/10/2016

Nous étions présents à Rennes pour PyConFr 2016. Voici notre compte-rendu à chaud.

Wagtail: How to use the Page model and its manager (part 2) Wagtail: How to use the Page model and its manager (part 2) 08/08/2016

The Page model has several methods specific to Wagtail. This is also the case of its manager. We ...

Wagtail : How to make your own content type models (part 1) Wagtail : How to make your own content type models (part 1) 29/07/2016

We are used to initialize our CMS directly from a web interface, often including lots of complex ...

Presentation of the latest Django CMS: Wagtail Presentation of the latest Django CMS: Wagtail 22/07/2016

Wagtail is a quite recent Django CMS. However, its young age does not keep it from having a lot of ...