Django Carton是一个简单而轻量级的购物车和愿望清单应用程序。
django-carton的Python项目详细描述
+------+ /| /| +-+----+ | django-carton helps you build your shopping | | | | cart and which list functionality. | +----+-+ |/ |/ +------+
- 很简单:您决定如何实现视图、模板和付款 处理。
- 它是轻量级的:购物车就在会话中。
- 它只是一个容器:你可以按照你想要的方式定义你的产品模型。
用法示例
视图:
from django.http import HttpResponse from carton.cart import Cart from products.models import Product def add(request): cart = Cart(request.session) product = Product.objects.get(id=request.GET.get('product_id')) cart.add(product, price=product.price) return HttpResponse("Added") def show(request): return render(request, 'shopping/show-cart.html')
我们假设您的产品是在应用程序中定义的 调用了products。
模板:
{% load carton_tags %} {% get_cart as cart %} {% for item in cart.items %} {{ item.product.name }} {{ item.quantity }} {{ item.total_price }} {% endfor %} You can also use this convinent shortcut: {% for product in cart.products %} {{ product.name }} {% endfor %}