djangodjango-crispy-forms

{{ form.non_field_errors }} with django-crispy-forms


I have the following django form using crispy-forms:

<div class="panel panel-default">
  <div class="panel-heading">
    <h2 class="panel-title">TEAM SELECTION</h2>
  </div>
  <div class="panel-body">
    <form action="" method="post">
        {% csrf_token %}
        <div>{{ form.non_field_errors }}</div>
        <div class="col-xs-12 col-sm-5 col-md-5 col-lg-5">{{ form.team1|as_crispy_field }}</div>
        <div class="col-xs-12 col-sm-5 col-md-5 col-lg-5">{{ form.team2|as_crispy_field }}</div>
        <div class="col-xs-12 col-sm-2 col-md-2 col-lg-2"><button type="submit" class="btn btn-primary btn-block"; margin-bottom: 2cm;>Submit</button></div>
    </form>
  </div>
</div>

Everything looks amazing except the {{ form.non_field_errors }} part. It just looks like a bullet list as follows:

Does anyone know how I can have make the {{ form.non_field_errors }} look as exciting as the rest of the form?


Solution

  • Try the as_crispy_errors filter:

    {% load crispy_forms_tags %}
    {{ form|as_crispy_errors }}