【发布时间】:2021-01-05 00:47:08
【问题描述】:
这是我的 main.html,我目前包括页眉和页脚
{% include "store/header.html" %}
{% block content %}
{% endblock content %}
{% include "store/footer.html" %}```
我的 header.html 示例:这是我试图呈现我的购物车的地方
<div class="shopping__cart">
<div class="shopping__cart__inner">
<div class="offsetmenu__close__btn">
<a href="#"><i class="zmdi zmdi-close"></i></a>
</div>
<div class="shp__cart__wrap">
{% for item in items %}
<div class="shp__single__product">
<div class="shp__pro__thumb">
<a href="#">
<img src="{{item.product.imageURL}}" alt="product images">
</a>
</div>
<div class="shp__pro__details">
<h2><a href="product-details.html">{{item.product.title}}</a></h2>
<span class="quantity">QTY: {{item.quantity}}</span>
<span class="shp__price">${{item.product.price|floatformat:2}}</span>
</div>
<div class="remove__btn">
<a href="#" title="Remove this item"><i class="zmdi zmdi-close"></i></a>
</div>
</div>
{% endfor %}
</div>
<ul class="shoping__total">
<li class="subtotal">Subtotal:</li>
<li class="total__price">${{order.get_cart_total|floatformat:2}}</li>
</ul>
<ul class="shopping__btn">
<li><a href="cart.html">View Cart</a></li>
<li class="shp__checkout"><a href="checkout.html">Checkout</a></li>
</ul>
</div>
</div>
我正在尝试将商品呈现到我的购物车中。
这是我的看法:
def header(request):
category = None
categories = Category.objects.all()
products = Product.objects.all()
if category_slug:
category = get_object_or_404(Category, slug=category_slug)
products = products.filter(category=category)
data = cartData(request)
cartItems = data['cartItems']
order = data['order']
items = data['items']
context = {'items':items, 'order':order, 'cartItems':cartItems, 'categories':categories, 'products':products, 'category': category}
return render(request, 'store/header.html', context)
但我不确定如何渲染它,因为它只是一个标题。也许我应该以不同的方式看待它。
【问题讨论】: