2

Remove django form field validation errors manually

 4个月前 阅读数 3
以下为 快照 页面,建议前往来源网站查看,会有更好的阅读体验。
原文链接: https://blog.mathieu-leplatre.info/remove-django-form-field-valiation-errors-manually.html
Remove django form field validation errors manually

Remove django form field validation errors manually

Tue 06 December 2011

Original post at Makina Corpus

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.

#django, #tips - Posted in the Dev category


© Copyright 2020 by Mathieu Leplatre. mnmlist Theme

Content licensed under the Creative Commons attribution-noncommercial-sharealike License.


猜你喜欢

关于极客头条


聚合每日国内外有价值,有趣的链接。