开发者

django form errors prints __all__

This code in the default login template:

{{ form.errors }}

Produces this html output when the account is inactive:

<ul class="errorlist">
  <li>__all__
    <ul class="errorlist">
      <li>This account is inactive.</li>
    </ul>
  </li>
</ul>

Why does it print the string _all_?

I'm using the developm开发者_如何学运维ent version by the way.


Ah, I should have used:

{{ form.non_field_errors }}

instead


If you, like me, still want to display ALL errors at once, you can loop over form.errors.items.

This line:

{{ form.errors }}

Becomes this: (or similar)

<ul class="errorlist">
    {% for key, value in form.errors.items %}
    <li>{% if key != '__all__' %}{{ key }} {% endif %}{{ value }}</li>
    {% endfor %}
</ul>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜