How to access a dictionary in a list in Django Template? -


in views.py have :

credits_total = course.objects.filter(dept = dept_code1, b_tech = 1, type = 1).values('sem').annotate(sum = sum('credits')) 

so credits_total has following:

credits_total = [{'sem': 3, 'sum': 19},{'sem': 4, 'sum': 20},{'sem': 5, 'sum': 21},{'sem':6,'sum':22},{'sem':7,'sum':21},{'sem':8,'sum':24}] 

i want somthing like:

{% in "012345" %}     ....     <b> {{credits_total[i]['sum']}} </b>     ... {% endfor %} 

how can access specific key in dictionary @ specific index in list?

i'm new django plz explain in detail. thank you!

python dictionaries best thought of unordered sets. shouldn't try index them... said, can iterate on dictionary data , print follows.

{% if credits_total %}     {% item in credits_total %}         sem:{{ item.sem }}, sum:{{ item.sum }}     {% endfor %} {% endif %} 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -