title: Django Template - Nested Dictionary Iteration
body: <p>My template receives from views.py following nested dictionary of shopping cart content.</p>
  <pre><code>{
  '20': 
      {'userid': 1, 
      'product_id': 20, 
      'name': 'Venus de Milos', 
      'quantity': 1, 
      'price': '1500.00', 
      'image': '/media/static/photos/pngegg.png'}, 
  '23': 
      {'userid': 1, 
      'product_id': 23, 
      'name': 'Bicycle', 
      'quantity': 1, 
      'price': '1000.00', 
      'image': '/media/static/photos/366f.png'}
  }
  </code></pre>
  <p>I am having problem with iteration through it.
  For example, when I am using following code,</p>
  <pre><code>{% for key, value in list %}
  
  {{ key }} {{ value }}
  
  {% endfor %}
  </code></pre>
  <p>instead of keys and values I receive just this:</p>
  <pre><code>2 0 
  2 3
  </code></pre>
  <p>My goal is to calculate grand total through multiplying quantity and price for each product and dding it all together with each product in cart.</p>
  <p>May sombody give me a hand on this, or at least help to figure out how to iterate properly through nested dictionary?</p>
  <p>i am using following lib for cart:
  <a href="https://pypi.org/project/django-shopping-cart/" rel="nofollow noreferrer">https://pypi.org/project/django-shopping-cart/</a></p>
  <p><strong>views.py:</strong></p>
  <pre><code>@login_required(login_url=&quot;/users/login&quot;)
  def cart_detail(request):
      cart = Cart(request)
      queryset = cart.cart
      context = {&quot;list&quot;: queryset }
      return render(request, 'cart_detail.html', context)
  </code></pre>
  <p><strong>SOLVED</strong> (kind of):
  Following your advice, I've wrote calculation for &quot;total&quot; in views.py
  BUT, since dictionary of product has 6 attributes, &quot;total&quot; is added 6 times in loop, for each product in cart.
  For now I've just added division by 6, but obviously this is not rational solution</p>
  <pre><code>def cart_detail(request):
      cart = Cart(request)
      queryset = cart.cart
  
      total_price=0
  
      for key, value in queryset.items():
          for key1, value1 in value.items():
              total_price = total_price + (float(value['quantity']) * float(value['price']))
      #Temporal decision
      total_price = total_price / 6
      
      context = {&quot;list&quot;: queryset, &quot;total_price&quot;: total_price }
      return render(request, 'cart_detail.html', context)
  </code></pre>