I
< <def dashboard_view(request):
carts = Cart.objects.filter(cart_user__isnull = False)
cartitems = CartItem.objects.all()
vegetables_dict = {}
for item in cartitems:
if item.stock_item.product_stockitem.name in vegetables_dict:
vegetables_dict[item.stock_item.product_stockitem.name] += item.quantity
else :
vegetables_dict[item.stock_item.product_stockitem.name] = item.quantity
context = {
'carts' : carts,
'cartitems' : cartitems,
'items' : vegetables_dict
}
return render(request, "maraicher/dashboard.html", context)
<
<table>
<thead>
<tr>
<th colspan="2"> Récapitulatif de récole</th>
</tr>
</thead>
<tbody>
<th>Produit</th>
<th>Quantité</th>
<div>{{items}}</div>
{% for key, value in items.item %}
<tr>
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<
<
{% for item in items %}
<tr>
<td>{{item}}</td>
<td>{{item.item}}</td>
</tr>
{% endfor %}
Вот как это должно быть в шаблоне Django:
{% for key, value in items.items %}
<tr>
<td>{{ key }}</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
Как отметил @user2390182, пропущена буква "s", правильный синтаксис
{% for key, value in items.items %}
Вы должны попробовать это
{{items}}
{% for item in items %}
<tr>
<td>{{item}}</td>
</tr>
{% endfor %}