-2

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?

3

2 Answers 2

-1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Is this answer meant for this question or did you post on the wrong one?
Can you explain with more detail.
-1

Hope this helps

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

as @AbdulAzizBarkat mentioned in the comment.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.