How can reference the last item in a list in a Django template? {{ list.-1.key }}

后端 未结 6 1791
星月不相逢
星月不相逢 2021-01-01 08:33

if I have a variable in the context of unknown length, for example;
list=[{\'key\':\'A\'},{\'key\':\'B\'},{\'key\':\'C\'}]

How can I get the last ob

6条回答
  •  轮回少年
    2021-01-01 09:24

    You can mark the last forloop by the following tags

    {% if forloop.last %} ... {% endif %}
    

    and add you special desire inside the tags.

提交回复
热议问题