Making a complex customized Django form template? Remember to include form.non_field_errors!
This drove me crazy for about 30 minutes.
If you’re making a heavily customized form template with Django, the newforms documentation suggests this format:
But, if you do any sort of non-field specific (form-level) validation, those validation messages won’t be returned to the user. So, instead of seeing a message like, “Both password fields must match,” the form just reloads without a explanation, confusing our poor end-users (and me for about 30 minutes)!
A quick #django IRC session later and I had the answer: form.non_field_errors
I’m no professional developer, but a lack of Google search results for this matter inspired me to make a quick post and tag it well so future Django form template customizers don’t pull their hair out.
(Sorry to post the code as images, but [hosted] WordPress doesn’t escape HTML enclosed in code blocks! Ridiculous.)
Filed under: internets, tech |
Tags: 0.96, attribute, dev, django, error, field, field specific, form, form wide, form-level, form.as_ul, form.errors, form.errors.all, form.field_errors, forms, forms.ValidationError, level, message, new forms, newforms, non, non-field, non-field-specific, non-specific, non_field_errors, python, release, specific, svn, validation, validationerror, validator


I didn’t even know IRC was still around. Nice.
Thats awesome, I never knew it before untill today. Great job.
Bit by this just this morning. Appreciate the post. I’m using Form Wizard and a custom layout to accomplish some mid wizard ajax validation. This post hit the spot on the form validation errors I was hitting.
Thanks!
Thanks for posting this, it helped me out