Display values ​from a dictionary in python

Viewed 48

I converted the python dictionary into a python object, but I can't display the values ​​of the sub-array D

Views.py

def dictToObject(request):
  dictionnaire={'A': 1, 'B': {'C': 2},'D': ['E', {'F': 3}],'G':4}
  obj=json.loads(json.dumps(dictionnaire))
  context={'obj':obj}
  return render(request,'cart/cart_detail.html',context)

cart_detail.html

  {{ obj.D[0] }}
  {{ obj.D[1].F }}

I get an error (Could not parse the remainder: '[0]' from 'obj.D[0]'), I don't know why?

2 Answers

Inside a {% %} tag, variables aren't surrounded by {{.

Hope this helps

{{ obj.D.0 }}
{{ obj.D.1.F }}
Related