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>
精彩评论