Home > Mobile >  Display values ​from a dictionary in python
Display values ​from a dictionary in python

Time:09-21

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?

CodePudding user response:

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

Try this:

{% ifequal num buildSummary_list.number %}

CodePudding user response:

Hope this helps

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