python - Django Template Tag Loop dictionary variable -


i've reading template tags posts regarding loop variable in key. apparently django not support loop variable in key , not sure how use custom template tag.

i wanted display this, how can achieve {% in mdata %} loop ?

{{ mdata.0.name }} {{ mdata.1.name }} {{ mdata.2.name }}  {{ mdata.0.age }} {{ mdata.1.age }} {{ mdata.2.age }} 

mdata list of dictionaries.

mdata = { "name":"alex", "age":"12"},{"name":"amy","age":"14"} ...

considering data in list of dictionaries such as:

my_data = [{"name" : "abc" , "age":20,...}, {} , {}...] 

you can access attributes of each dictionary in template way:

{% dict in my_data %} <!-- here dict each of dictionary in my_data --> <!-- can access elements of dict using dot syntax, dict.property -->    {{ dict.name }}, {{ dict.age }}, ... {{ dict.property }} {% endfor %} 

reference links: django templating language

if want structure elements in order specifed, can this:

name list: {% dict in my_data %} my_data.name {% endfor %}  age list: {% dict in my_data %} my_data.age {% endfor %}  ... prpoerty list: {% dict in my_data %} my_data.property {% endfor %} 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -