If I look in Django's forms.py, as_p()
calls _html_output()
, which styles field errors with self.error_class()
(although I can't locate the definition of that).
However, _html_output()
does NOT style non_field_errors
(a.k.a. top_errors in the code).
How does one style the non-field errors? Cut and paste all of _html_output?
I am using Django 1.0.
I use this template to style non fields errors:
{% if form.non_field_errors %}
<div class="non-field-errors">
{% for err in form.non_field_errors %}
<p class="form-error">{{ err }}</p>
{% endfor %}
</div>
{% endif %}
In your template you can access {{ form.non_field_errors }} and render them however you like. Here's how the Django admin handles them for example: http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templates/admin/change_form.html#L40
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With