Django Forms:显示错误

时间:2016-11-10 19:29:05

标签: django forms

我有以下代码:

            {% if form.errors %}
                <div class="alert alert-danger" role="alert">
                  <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
                  <span class="sr-only">Error:</span>
                  {{ form.errors }}
                </div>
            {% endif %}

这产生了以下结果:

error picture

我想删除子弹点而不包括__ all __ part。

感谢任何帮助,非常感谢,Alan。

如果形式的干净部分如下可能会有所帮助:

def clean(self):
    cleaned_data = self.cleaned_data # individual field's clean methods have already been called
    team1 = cleaned_data.get("team1")
    team2 = cleaned_data.get("team2")
    if team1 == team2:
        raise forms.ValidationError("You picked the same team!")

    return cleaned_data

1 个答案:

答案 0 :(得分:0)

您可以尝试这样做:

{% if form.errors %}
    {% for error in form.errors %}
        <div class="alert alert-danger" role="alert">
            <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
            <span class="sr-only">Error:</span>
            {{ error }}
        </div>
    {% endfor %}
{% endif %}

我认为应该有效。你得到了什么输出?