![]() |
VOOZH | about |
A shopping cart allows users to collect and manage items they want to purchase before proceeding to checkout. We will build a simple shopping cart using Django and learn how to create models, views, templates and URLs to add, view and remove items from the cartโstep by step.
Prerequisites:
To start the project and app use this command
django-admin startproject ecommerce
cd ecommerce
python manage.py startapp cart
Now add this app to the 'settings.py'.
๐ Screenshot-2023-10-06-170834
Your database schema is the foundation of the app. We'll create two models:
Register your models so you can add/edit products and cart items via Djangoโs admin interface:
The views will handle displaying products, managing the cart, adding/removing items and rendering appropriate templates.
Adding a cart to a Django web page is a crucial skill for e-commerce apps. If you're looking to build more complex applications, the Django Web Development Course will guide you through advanced concepts.
Displays all products with their image, description, price and an Add to Cart button.
Shows the current items in the cart with quantity, price and a remove option, along with the total cost.
In cart/urls.py, map URLs to the views:
Include these URLs in the main ecommerce/urls.py:
settings.pyConfigure Django to serve static and media files during development. In your project's settings.py file, add the following:
Generate and apply database migrations:
python manage.py makemigrations
python manage.py migrate
Run the server with the help of following command:
python manage.py runserver
Now, Go to the http://127.0.0.1:8000/admin/ and add the Images, name and its description.
๐ Screenshot-from-2023-10-05-01-05-20
Output