3👍
✅
Finally I got it working by passing out.items()
to the template and iterating over out
, so:
views.py
context = {'out': out.items()}
return render(request, 'components_by_season.html', context)
in my temmplate:
{% for k,v in out %}
<p>{{ k }}: {{ v.total_qty }}</p>
{% endfor %}
4👍
Assuming this is actually your real code, my_var
is a dict, not a list. Iterating over a dict just gives you the keys; if you want the values as well, you should iterate over .items()
. So:
<ul>
{% for k, v in my_var.items %}
<li>{{ k }}: {{ v.total_qty }}</li>
{% endfor %}
</ul>
Note also, there is no product
key; the name of the product is just the key in the outer dict.
- [Django]-How to get checkbox value in django?
- [Django]-Search multiple fields of django model without 3rd party app
- [Django]-How do I fix this error in Python Django involving request.user.is_authenticated() and bool object not callable?
- [Django]-Django method to change User email not working
- [Django]-Overriding Django Admin's main page? – Django
- [Django]-Customize user's admin panel permission only to read(not delete,edit or add)
- [Django]-Which is a better way to check request conditions?
- [Django]-Ignore_user_abort php simil in Django/python?
- [Django]-Where to you monkey patch the Django user model?
Source:stackexchange.com