I am trying to compare the length of a dictionary inside a django template
For example, I would like to know the correct syntax to do the following:
{% if error_messages %} <div class='error'> {% if length(error_messages) > 1 %} Please fix the following errors: <div class='erroritem'> {% for key, value in error_messages.items %} <br>{{ value }} {% endfor %} </div> {% else %} {% for key, value in error_messages.items %} {{ value }} {% endfor %} {% endif %} </div> {% endif %}
You could do this, using the length filter and the ifequal tag:
Anything else will have to go down the path of custom tags and filters.