Check if an array is not empty in Jinja2

后端 未结 7 1130
萌比男神i
萌比男神i 2021-02-06 20:48

I need to check if the variable texts is defined or not in index.html.

If the variable is defined and not empty then I should render the loop.

7条回答
  •  闹比i
    闹比i (楼主)
    2021-02-06 21:05

    This is a neat and simple solution that worked well for me!

    {% if texts is defined and texts[0] is defined %}
        ...
    {% endif %}
    

提交回复
热议问题