dangerChihuahua007
dangerChihuahua007

Reputation: 20895

In a Django template with a form, how can one display form errors that are not specific to a field?

I have a form in a Django template. I am aware that I can display errors related to a specific field via

 {% for e in field.errors %}{{ e }}{% endfor %}

However, how do I obtain errors specific to the form itself such as the errors returned by an overall clean function in a form?

Thanks!

Upvotes: 0

Views: 1084

Answers (2)

Jan Pöschko
Jan Pöschko

Reputation: 5570

You can access non-field errors via form.non_field_errors(). See https://docs.djangoproject.com/en/dev/ref/forms/validation/#form-and-field-validation.

Upvotes: 3

Ismail Badawi
Ismail Badawi

Reputation: 37187

Use {{ form.non_field_errors }}.

Upvotes: 2

Related Questions