stackit
stackit

Reputation: 3106

comparing length of dictionary in jinja flask template

I pass the dictionary errs to a jinja template for flask server:

{% if  not errs|length  equals 0  %}

But, the following error occurs:

TemplateSyntaxError: expected token 'end of statement block', got 'equals'

I tried various combinations but keep getting different errors, so how to compare length of a dictionary in the template if construct?

Upvotes: 10

Views: 18346

Answers (1)

DazWorrall
DazWorrall

Reputation: 14210

This works for me (Jinja 2.7):

{% if {}|length == 0 %}
    is zero
{% endif %}

Upvotes: 24

Related Questions