1from django.contrib import messages
2
3<--Change setting under settings.py
4from django.contrib.messages import constants as messages
5MESSAGE_TAGS = {
6 messages.ERROR: 'danger'
7}
8-->
9
10{% for message in messages %}
11<div class="alert alert-{{ message.tags }} mb-0 alert-dismissible fade show" role="alert">
12 <strong>Message: </strong> {{ message }}
13 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
14 <span aria-hidden="true">×</span>
15 </button>
16</div>
17{% endfor %}
18
19
20<--Add message
21messages.debug(request, '%s SQL statements were executed.' % count)
22messages.info(request, 'Three credits remain in your account.')
23messages.success(request, 'Profile details updated.')
24messages.warning(request, 'Your account expires in three days.')
25messages.error(request, 'Document deleted.')
26-->
1{% if messages %}
2<ul class="messages">
3 {% for message in messages %}
4 <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
5 {% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}Important: {% endif %}
6 {{ message }}
7 </li>
8 {% endfor %}
9</ul>
10{% endif %}
11
1{% if messages %}
2<ul class="messages">
3 {% for message in messages %}
4 <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
5 {% endfor %}
6</ul>
7{% endif %}
8
1{% if messages %}
2 {% for message in messages %}
3 <p id="messages">{{message}}</p>
4 {% endfor %}
5{% endif %}
1from django.contrib import messages
2messages.add_message(request, messages.INFO, 'Hello world.')
3
1from django.contrib.messages import constants as messages
2MESSAGE_TAGS = {
3 messages.INFO: '',
4 50: 'critical',
5}
6