Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogrocker/85381ff0feb0955d0ee7d7e5bb29ae16 to your computer and use it in GitHub Desktop.
Save dogrocker/85381ff0feb0955d0ee7d7e5bb29ae16 to your computer and use it in GitHub Desktop.
Show messages and errors in Django templates. Useful to just throw in a base template.
{% if messages %}
{% for message in messages %}
<div class="alert {% if message.tags %} alert-{{ message.tags }}{% endif %}">{{ message|safe }}</div>
{% endfor %}
{% endif %}
{% if form.errors %}
<div class="alert alert-error">
<h4>Please fix the following errors</h4>
<ul>
{% for field in form %}
{% if field.errors %}
{% for error in field.errors %}
<li><a href="#id_{{ field.name }}" class="error">{{ error|escape }}</a></li>
{% endfor %}
{% endif %}
{% endfor %}
</ul>
{% if form.non_field_errors %}
{{ form.non_field_errors }}
{% endif %}
</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment