Skip to content

Instantly share code, notes, and snippets.

@ricardodani
Forked from dimitrov/messages.html
Created March 25, 2022 21:59
Show Gist options
  • Save ricardodani/9629ef8c0501ef27b92f66b65f26c5a7 to your computer and use it in GitHub Desktop.
Save ricardodani/9629ef8c0501ef27b92f66b65f26c5a7 to your computer and use it in GitHub Desktop.
Bootstrap Alerts for Django
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible text-center" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>{% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}Error{% else %}{{ message.tags|title }}{% endif %}!</strong> {{ message }}
</div>
{% endfor %}
{% endif %}
from django.contrib.messages import constants as messages
MESSAGE_TAGS = {
messages.ERROR: 'danger'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment