[Fixed]-Django, loop over all form errors


Form errors in Django are implemented as an ErrorDict instance (which is just a subclass of dict with extras). Try a slight adjustment to your template for loop syntax:

{% for key, value in form.errors.items %}


Are you, by any chance, looking for form.non_field_errors? That is how you would get access to the errors that aren’t associated with a particular field.

{% if form.non_field_errors %}
    {{ form.non_field_errors.as_ul }}
{% endif %}

Check the forms.py test suite as well for another example. Search for form.non_field_errors

Leave a comment