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

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

我有以下使用 crispy-forms 的 django 表单:

<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>

{{ form.non_field_errors }} 部分外,一切看起来都很棒。它看起来就像一个项目符号列表,如下所示:

有谁知道我怎样才能让 {{ form.non_field_errors }} 看起来像表格的其他部分一样令人兴奋?

试试 as_crispy_errors 过滤器:

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