How can I check the size of a collection within a Django template?

前端 未结 7 1514
南旧
南旧 2020-12-12 21:31

I have a list in my Django template. I want to do something only if the size of the list is greater than zero.

I have tried myList|length and m

7条回答
  •  执笔经年
    2020-12-12 21:57

    You can try with:

    {% if theList.object_list.count > 0 %}
        blah, blah...
    {% else %}
        blah, blah....
    {% endif %} 
    

提交回复
热议问题