0

I am using the following code to access the first message in Django template,

{% if messages %}
    {% for message in messages %}
        {%  if forloop.first  %}
                {{ message }}
        {% endif %}
    {% endfor %}
{% endif %}

How I can achieve the same without using the for loop in a single statement.

1 Answers1

3

Following should work:

{% if messages %}
    {{ messages.0 }}
{% endif %}
Heval
  • 338
  • 3
  • 11