George Godik
George Godik

Reputation: 1716

referencing a key/value in django-templates after applying a filter

say I have the following list that I provide to a django template

stuff= [ { 'a':2 , 'b':4 } , { 'a',7} ]

I want to access the 'a' attribute of the first element. I can't quite get the syntax right.

{{stuff|first}} 

gives me the first element, but

{{stuff|first.a}} 

is a dead end ( and weird )

and I can't seem to find a attribute filter. Short of writing one myself, is there template language syntax for what I want to do ?

stuff[0].a is no go as well

Upvotes: 1

Views: 331

Answers (1)

Fred Larson
Fred Larson

Reputation: 62123

This is off the top of my head, but I think it is

{{ stuff.0.a }}

Upvotes: 4

Related Questions