Django Shopping Cart is a Django app to store product in cart.
Detailed documentation is in the “docs” directory.
Quick start
Add “cart” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'cart', ] Add below line to settings context_processor:: 'cart.context_processor.cart_total_amount' CART_SESSION_ID = 'cart'You can use the urls in following way:
from django.urls import path from . import views urlpatterns = [ path('cart/add/<int:id>/', views.cart_add, name='cart_add'), path('cart/item_clear/<int:id>/', views.item_clear, name='item_clear'), path('cart/item_increment/<int:id>/', views.item_increment, name='item_increment'), path('cart/item_decrement/<int:id>/', views.item_decrement, name='item_decrement'), path('cart/cart_clear/', views.cart_clear, name='cart_clear'), path('cart/cart-detail/',views.cart_detail,name='cart_detail'), ]
- You should have a Product model & Below field is mandatory
name = models.CharField(max_length=255) image = models.ImageField(upload_to=’products/’) price = models.FloatField()
Then views.py should like like this:
from django.shortcuts import render, redirect from store.models import Product from django.contrib.auth.decorators import login_required from cart.cart import Cart @login_required(login_url="/users/login") def cart_add(request, id): cart = Cart(request) product = Product.objects.get(id=id) cart.add(product=product) return redirect("home") @login_required(login_url="/users/login") def item_clear(request, id): cart = Cart(request) product = Product.objects.get(id=id) cart.remove(product) return redirect("cart_detail") @login_required(login_url="/users/login") def item_increment(request, id): cart = Cart(request) product = Product.objects.get(id=id) cart.add(product=product) return redirect("cart_detail") @login_required(login_url="/users/login") def item_decrement(request, id): cart = Cart(request) product = Product.objects.get(id=id) cart.decrement(product=product) return redirect("cart_detail") @login_required(login_url="/users/login") def cart_clear(request): cart = Cart(request) cart.clear() return redirect("cart_detail") @login_required(login_url="/users/login") def cart_detail(request): return render(request, 'cart/cart_detail.html')In the template you can use the url in folowing way:
<a href="{% url 'cart_add' product.id %}">Add To Cart</a> <a href="{% url 'cart_clear' %}">Clear Cart</a> <a href="{% url 'item_increment' value.product_id %}">Increament</a> <a href="{% url 'item_decrement' value.product_id %}">Decrement</a>To view the cart detail page use the below code
{% load cart_tag %}
Total Length :: {{request.session.cart|length}}
Cart Detail:
{% for key,value in request.session.cart.items %}{{value.name}} {{value.price}} {{value.quantity}} {{value.image}} Total {{ value.price|multiply:value.quantity }}
{% endfor %}
Metadata
Release files for django-shopping-cart 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-shopping-cart-0.1.tar.gz | 4.5 kB | Without provenance | Details for django-shopping-cart-0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_shopping_cart-0.1-py3-none-any.whl | Python 3 | none | any | Details for django_shopping_cart-0.1-py3-none-any.whl |
Total release size: 10.9 kB
Release files / django-shopping-cart-0.1.tar.gz
| Download URL | django-shopping-cart-0.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01fb2ebf63e4e0ee34f9ed4ac9ee2cad65bbcdbd1519ad0165820d01dc59da83
|
|
BLAKE2b-256 checksum How to use checksums |
64fa93122af88f1fd4c79bd64867ade9928cee413cc1d22009df2ea6cee58e14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.9
|
Release files / django_shopping_cart-0.1-py3-none-any.whl
| Download URL | django_shopping_cart-0.1-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd125c07968354c7967782e735b888d61b3e76139ab9babfcd3eae25b559d38c
|
|
BLAKE2b-256 checksum How to use checksums |
7d11f8952063c9b23b5ac0810ea748eaab9e2a65d627aa26b3095e9a74f15b6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.9
|
Security for django-shopping-cart 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.