Hi all, I have a form and a formset that are passed to a template. I would like to display any errors at the top of the template, using something like this:
{% if form.errors or form.non_field_errors or formset.errors or formset.non_form_errors %} <div class="error"> <p>The operation could not be performed because one or more error(s) occurred.<br />Please resubmit the form after making the following changes:</p> {% if form.non_field_errors %} {{form.non_field_errors}} {% endif %} {% if form.errors %} <ul> {% for field in form %} {% if field.errors %} {% for error in field.errors %} <li>{{field.label}}: {{error}}</li> {% endfor %} {% endif %} {% endfor %} </ul> {% endif %} {% if formset.non_form_errors %} {{form.non_form_errors}} {% endif %} {% if formset.errors %} {% for form in formset.forms %} {# formset.errors is a list of dictionaries #} {% if form.errors %} <p>Choice #{{forloop.counter}}:</p> <ul> {% for field in form %} {% if field.errors %} {% for error in field.errors %} <li>{{field.label}}: {{error}}</ li> {% endfor %} {% endif %} {% endfor %} </ul> {% endif %}g {% endfor %} {% endif %} </div> {% endif %} The problem is, apparently, that formset.errors is never empty, since is a list of empty dictionaries (is this correct?). The result is that I always get the: <p>The operation could not be performed because one or more error(s) occurred.<br />Please resubmit the form after making the following changes:</p> outputed, even if there are no errors in the form/formset (at least I think this is the reason for that). Any thoughts on how to avoid this behaviour? How can I check if a list contains empty dictionaries within the template without iterating through the list elements? Thanks. Paolo -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.