28👍
I use this template to style non fields errors:
{% if form.non_field_errors %}
<div class="non-field-errors">
{% for err in form.non_field_errors %}
<p class="form-error">{{ err }}</p>
{% endfor %}
</div>
{% endif %}
10👍
In your template you can access {{ form.non_field_errors }} and render them however you like. Here’s how the Django admin handles them for example: http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templates/admin/change_form.html#L40
- Django how to reconnect after DatabaseError: query timeout
- Background processing in Django without Celery
- Django/Python – Check a date is in current week
- Django + Postgres: A string literal cannot contain NUL (0x00) characters
- Subclassing Django ModelForms
8👍
Options:
Both {{ form.non_field_errors }}
and {{ form.non_field_errors.as_ul }}
do the same thing.
{{ form.non_field_errors.as_text }}
displays the errors with an *
in front of the text.
This article is also helpful in explaining why the *
will not be removed django ticket
- How to create or register User using django-tastypie API programmatically?
- How to downgrade from Django 1.7 to Django 1.6
0👍
Can be done without complicating the template language. In Django 3 the non_field_errors list has classes "errorlist nonfield", so you can simply use CSS to style them:
In your CSS file:
.errorlist.nonfield {
color: red;
}
In your html template:
{{ form.as_p }}