Lesson 1: Building an E-Commerce Shopping Cart Using Django 2.0 and Python 3.6

Introduction

Hey and welcome to this Python Django tutorial series. My name is Henry Mbugua and I will be taking you through the various aspect of building a shopping cart application using Django 2.0 web framework and Python 3.6. I am a software developer at Muva Technologies where our main focus is to offer services around mobile solutions(Apps), web solution and websites, payments integration, web hosting and domains, and last but not least, consultancy and training.

Why create a shopping cart application?

Previously, we learnt how to build a blog application in Django 1.11 and Python 3.6. I think it’s finally time for a new bigger project, due to how technology is changing the way we do business, I decided to go in e-commerce direction. On-line shopping is becoming a large part of Internet commerce and creating a shopping cart from ground up is a huge undertaking that require a great deal of talent and knowledge to write.

How does a shopping cart works? Basically, when you visit a site like ebay, you are able to view products in a given category, you can add products to cart, you can also go to different pages and select other products that you need to add to your cart. You can also remove item from your shopping cart and finally, you are able to purchase your products.

It seems like a rather simple process on this side of the curtain, but behind the scenes, it’s quite a difficult task to get that products data to move along from one page to another as the site visitors shops around. So, I think it will be an interesting tutorial and am looking forward to that. One important note, I don’t have this project finished right now. I think it will be fun to build this project together, of course I still do prepare the individual lessons. The reason I use this approach is to build something from ground up without having a finished product because in a real world project, you don’t have a finished product, right!

Enough with the talking, lets get into it, shall we. Here are the topics that we will cover in this tutorial series:

  • Lesson 1: Building an E-Commerce Shopping Cart Using Django 2.0 and Python 3.6

  • Lesson 2: Creating Our Shop app and designing product model in Django 2.0 and Python 3.6

Creating Virtual Environment

It’s always a better programming practice to create a python virtual environment and in this project we will create a virtual environment. I am using Linux Os and if you are using Mac Os or Windows, please leave a comment below this lesson on how to create python virtual environment on those platform. I have folder on my desktop called djangoShop, I will create my virtual environment in this folder, On my terminal, I will navigate to djangoShop folder and run the following command: virtualenv -p /usr/bin/python3 onlineshop

Here is my terminal output after running the above command.

The above command created a python virtual environment with the name onlineshop. To use our virtual environment, we actually need to activate it. To activate our virtual environment run the following command: source onlineshop/bin/activate At the beginning of the line on your terminal, you will see the name of your virtual environment and that is how you know that your environment is active. To deactivate your virtual environment simply type deactivate and hit enter.

NB: Every time you work on your virtual environment, always remember to activate it.

Now that our virtual environment is activated, let’s install Django web framework by running the following command: pip install Django Here is the output of my terminal.

The above command install latest Django web framework. In our case is Django 2.0.1

To start our e-commerce project run the following command: django-admin startproject ecommerce this command creates a our django project called ecommerce. On your terminal, navigate to our project folder by typing the following command: cd ecommerce To run our development server run the following command: python manage.py runserver here is the output of my terminal.

Now that our server is up and running, on your browser navigate to: http://127.0.0.1:8000/ You should see the following output.

Goals achieved in this lesson

  • We have given the reason for creating a shopping cart project.

  • We have created a virtual environment.

  • We have installed Django web framework in our virtual environment.

  • We have created our project and run the development server.

With that we conclude our first lesson, to get the code visit building an E-Commerce Shopping Cart application. See you in lesson 2.

Facebook Comments
Get free email updates!
Signup now and receive an email once we publish new content.
We respect your privacy

Henry Mbugua

I am a Junior Developer ready to enter major leagues. My professional ambition is to stay versatile and be able to fill different roles within a product group. As such, I have been learning technology across frontend and backend.