Django project – Creating a Basic E-commerce Website for Displaying Products
Last Updated :
24 Feb, 2022
Project Title – Basic Ecommerce Website using Django
Django is a powerful framework based on python. Here we will see how to create a basic e-commerce website in Django. This project includes storing products in the database and show them on the website.
Refer to the following articles to check how to create a project and an app in Django.
How to Create a Basic Ecommerce Website using Django?
Now when you have successfully installed Django. Create a new project –
django-admin startproject ecom
Now create a new app called frontend inside the ecom project. Now we have 1 project and 1 app inside of that project.]
django-admin startapp frontend
Directory structure –

Creating URLs –
In ecom> urls.py add the following lines. This file handles main project URLs. But we don’t want to disturb it, so we will do our work in frontend > URLs.py. And for that we need to include frontend > URLs inside the ecom> URLs.
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('frontend.urls')),
]
Creating Models –
Add a product model here.
class Product(models.Model):
productname = models.CharField(max_length=200)
price = models.DecimalField(max_digits=5, decimal_places=2)
description = models.TextField()
image = models.CharField(max_length=5000, null=True, blank=True)
To know more about Django models, check out – Django Models
Register Models into admin –
Just after creating model, we should register that form into admin.py.
from django.contrib import admin
from .models import *
admin.site.register(Product)
Creating Views for Displaying Products –
In frontend > views.py we write a function to get and display products from our database.
from django.shortcuts import render
from .models import *
def products(request):
products = Product.objects.all()
return render(request, 'products.html', {'products':products})
Creating Url for products –
Here we will set dynamic URL which can be useful to display our products. In frontend > urls.py
from django.urls import path
from . import views
urlpatterns = [
path('products/', views.products, name='products'),
]
Creating Template –
Creating template depends upon how you want to display products on website. For displaying products we have shared a simple code. Add it in frontend > templates > products.html
{% for product in products %}
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="{{ product.image }}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">{{ product.productname }}</h5>
<p class="card-text">{{ product.description }}</p>
<p class="card-text">Price - {{ product.price }}</p>
<a href="#" class="btn btn-primary">Buy Now</a>
</div>
</div>
{% endfor %}
Makemigrations and Migrate –
Now its time to migrate our model into database. First, we have to create migrations. For that type following code into terminal.
python manage.py makemigrations
After creating migrations type following code to apply those migrations
python manage.py migrate
To know more about makemigrations and migrate, check out – Basic App Model – Makemigrations and Migrate
Creating Superuser –
Now, create Django superuser for handling admin stuff. Type following command in terminal
django-admin createsuperuser
Then it will ask for username, email and password.
Run the app
After creating superuser, in terminal type,
python manage.py runserver
to start the server and go to admin panel (http://localhost:8000/admin) and add some products to the database.
Output –

Thats it. Your basic eCommerce site is ready where you can display your products
Similar Reads
Django Introduction | Set 2 (Creating a Project)
Note- This article is in continuation of Django introduction. Popularity of Django Django is used in many popular sites like as: Disqus, Instagram, Knight Foundation, MacArthur Foundation, Mozilla, National Geographic etc. There are more than 5k online sites based on Django framework. ( Source ) Sit
3 min read
How to Create a Basic Project using MVT in Django ?
Prerequisite - Django Project MVT Structure Assuming you have gone through the previous article. This article focuses on creating a basic project to render a template using MVT architecture. We will use MVT (Models, Views, Templates) to render data to a local server. Create a basic Project: To initi
2 min read
E-commerce Product Catalog using Django
Django is an excellent choice for building a robust product catalog. Django, a high-level Python web framework, provides a solid foundation for creating feature-rich and scalable e-commerce websites. In this article, we will explore how to build an e-commerce product catalog using Django. E-commerce
4 min read
Top 10 Django Projects For Beginners With Source Code
When it comes to software development in general, all development is run by websites on the internet. Even when you arenât actively looking for web development or a Full stack developer role, having worked on Django Projects or any web development projects will substantially improve your portfolio r
9 min read
E-commerce Website using Django
This project deals with developing a Virtual website âE-commerce Websiteâ. It provides the user with a list of the various products available for purchase in the store. For the convenience of online shopping, a shopping cart is provided to the user. After the selection of the goods, it is sent for t
11 min read
E-commerce Website using Tailwind and React using Django
Our e-commerce website, "ECOM," aims to offer users a smooth online shopping experience. We use Tailwind CSS for styling, React for interactive user interfaces, and Django for a strong backend. Shopify features a wide range of products across different categories, with functionalities like user auth
6 min read
Joke Application Project Using Django Framework
Django is a high-level Python-based Web Framework that allows rapid development and clean, pragmatic design. Â It is also called batteries included framework because Django provides built-in features for everything including Django Admin Interface, default database SQLlite3, etc. Today we will create
2 min read
When to Use Django? Comparison with other Development Stacks
Prerequisite - Django Introduction and Installation When to Use Django and Why? After getting to know the basics of Python, one should know when to use Django and why? Django is a high-level python based web framework which allows you to quickly create web applications without all of the installatio
4 min read
7 Mistakes You Should Avoid While Building a Django Application
Django...We all know the popularity of this Python framework. Django has become the first choice of developers to build their web applications. It is a free and open-source Python framework. Django can easily solve a lot of common development challenges. It allows you to build flexible and well-stru
6 min read
Best practices for Professional Developer - Django Framework
Django is an open-source, Python-based framework for building web applications. To make our Django code more readable and efficient we should follow a certain set of rules/practices. These should not be seen as the right way or the only way to work with Django, but instead best practices to work wit
3 min read