I love how Django performs form validation. However, I want to override the way the errors get displayed. I want to send form validation errors to the top of my web page (to a specific div tag) instead of letting Django display errors next to the form fields that are invalid. Any suggestions?
views:
179answers:
2You can easily do this by simply specifying {{ form.errors }}
at the top of your template, rather than putting {{ field.errors }}
at each field level.
I suspect from your question though that you're just using the {{ form.as_p }}
tag, or one of its brethren, to output the whole form in one go. Don't do this if you want to customise the display at all. It's not very difficult to replace it with a simple for loop to go through each field and display its label_tag
and the field itself, and you benefit hugely from the increased control.
Daniel pointed you in the right direction. See the documentation here:
http://docs.djangoproject.com/en/dev/topics/forms/#customizing-the-form-template
"Each named form-field can be output to the template using {{ form.name-of-field }}, which will produce the HTML needed to display the form widget. Using {{ form.name-of-field.errors }} displays a list of field errors...."