开发者

Help with django filters

开发者 https://www.devze.com 2023-01-01 05:51 出处:网络
I am have a list of \"Entries\" I want to get the first entry in the list\'s \"title\". In the template I tried writing

I am have a list of "Entries"

I want to get the first entry in the list's "title".

In the template I tried writing

{{ Entries|first.title }} 

But it results in an erro开发者_StackOverflow中文版r.

Is there a way to achieve this without writing a loop or doing it in the view?


Assuming you passed a list of Entries to the template under the name 'Entries',

{{ Entries.0.title }}

will give you the title of the first entry in the list. The first filter isn't the shortest path to where you want to go in this case.

0

精彩评论

暂无评论...
验证码 换一张
取 消