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 development version by the way.
The is_valid() method is used to perform validation for each field of the form, it is defined in Django Form class. It returns True if data is valid and place all data into a cleaned_data attribute.
cleaned_data is where all validated fields are stored.
Use the has_changed() method on your Form when you need to check if the form data has been changed from the initial data. has_changed() will be True if the data from request.
{{ form.as_p }} – Render Django Forms as paragraph. {{ form.as_ul }} – Render Django Forms as list.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With