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

后端 未结 6 1799
星月不相逢
星月不相逢 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:38

    In my case I find this solution: {{object_list.last.id}} very useful on expression like this: {% url 'my-url' object_list.first.id object_list.last.id %}

提交回复
热议问题