Rendering non_field_errors with render_form template tag

13 views
Skip to first unread message

Nathan Smith

unread,
Nov 29, 2017, 12:51:21 PM11/29/17
to Django REST framework
So I'm having a hard time figuring out how I can render non field errors for both validated and un-validated forms. I have created a templatepack and in form.html i do this:

{% load rest_framework %}

{% if form.errors %}
    {% for error in form.errors.non_field_errors %}
        <div class="alert alert-danger" style="width:100%;">{{ error }}</div>
    {% endfor %}
{% endif %}
{% for field in form %}
  {% if not field.read_only %}
    {% render_field field style=style %}
  {% endif %}
{% endfor %}


This works for validated forms and I get a proper error message, but when I pass it an un-validated form I get an unhandled exception:

You must call `.is_valid()` before accessing `.errors`.


Anyone know of a way to display non field errors for both validated and un-validated forms?
Reply all
Reply to author
Forward
0 new messages