Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django message template tag checking

I want to check whether the message tag are INFO ?

How to check that in the template file?

I tried this but it didn't work:

{% if messages %}
    <ul>
        {% for message in messages %}
            <li>
                {% if message.tag == "INFO" %}
                    {{ message }}
                {% endif %}
            </li>
        {% endfor %}
    </ul>
{% endif %}

I even tried other combinations like message.tag.info == "INFO" etc but they didn't seem to work. What is the correct way of checking it?

like image 239
Sibi Avatar asked May 23 '13 10:05

Sibi


1 Answers

Using bootstrap

{% block messages %}
    {% if messages %}
        {% for message in messages %}
            <div class="alert alert-{{ message.tags }}">  <!-- singular -->
                <a class="close" data-dismiss="alert">×</a>
                {{ message|safe }}
            </div>
        {% endfor %}
    {% endif %}
{% endblock %}

So it's {{ message.tags }} you're looking for

like image 75
Hedde van der Heide Avatar answered Oct 07 '22 18:10

Hedde van der Heide