Django Templating: how to access properties of the first item in a list

Viewed 58019

Pretty simple. I have a Python list that I am passing to a Django template.

I can specifically access the first item in this list using

{{ thelist|first }}

However, I also want to access a property of that item... ideally you'd think it would look like this:

{{ thelist|first.propertyName }}

But alas, it does not.

Is there any template solution to this, or am I just going to find myself passing an extra template variable...

4 Answers

a potentially clearer answer/syntax for accessing a ManyToManyField property in an object list provided to the django template would look like this:

{{ object_list.0.m2m_fieldname.all.0.item_property }}
Related