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.)
Possibly related posts: (automatically generated)
Filed under: internets, tech | 13 Comments
Tags: error, field, svn, dev, form, django, python, new forms, newforms, validation, form-level, level, specific, field specific, non-field-specific, non, validator, form wide, non_field_errors, form.errors, form.field_errors, release, 0.96, form.as_ul, forms.ValidationError, validationerror, forms, attribute, non-field, non-specific, message, form.errors.all
-
Recent Comments
Castrated Yuppie on Illegal taxis suck, but they… What4 on More proof that Microsoft hate… WTF on More proof that Microsoft hate… Roy Osaki on Satellite TV: How did it … SFMTA CEO Nat Ford L… on Muni Chief Nat Ford on KQED… -
Top Posts
- Making a complex customized Django form template? Remember to include form.non_field_errors!
- More proof that Microsoft hates Apple: Office on Mac OS X sucks.
- How much is a San Francisco taxi medallion worth?
- Illegal taxis suck, but they're a symptom of insufficient supply, not lax enforcement.
- When should public transportation systems be private?
- GTA vs. Real Life: Taxi Driving
- Satellite TV: How did it start?
- Cab driving: earnings update
Tags
ads bus busses cab cabbie california city demand driving earnings econ economics fee gate graveyard increase local lrt macro media micro muni municipal night npr online pedestrian planning policy politics pricing public radio rail regulation san francisco sf shift taxi taxicab traffic transit transport transportation work


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
Thank you for your post.
Also documented here : http://code.djangoproject.com/browser/django/trunk/docs/ref/forms/validation.txt?rev=8511
Regards.
this helped alot thanks
I am new to django .
my form renders as html code
Username:
It does not display the actual text box .
Please assist .
Thanks for the great tip. I couldn’t find this anywhere in Django’s documentation.
There is however a strange thing going on, form.non_field_errors.as_ul does add the tags (I am using Django 1.0). I used a workaround by iterating manually through the non_field_errors.
Thanks so much!
I was halfway through making a custom form and view and all sorts of mess to try and get at the __all__ errors field that the template system won’t show but contained the all-important “invalid username/password” error. Luckily your post (and shortly, a git reset) saved the day!
THANK YOU THANK YOU THANK YOU.
You are my hero!! Without this post I would have been banging my head against the wall all day!
Thanks! Just ran into the exact same issue — this was very helpful!
Thanks! This solved my problem.