1922 B.SC Cs Batchno 9
1922 B.SC Cs Batchno 9
DJANGO FRAMEWORK
Submitted By
Intern at
DEPARTMENT OF Bachelor of Computer Application (BCA)
BONAFIDE CERTIFICATE
Internal Guide
Soumitra Das
I, Raihan Mistry and other team members hereby declare that the Project Report entitled “E-
Guidance of MR. Soumitra das is submitted in partial fulfillment of the requirements for the
DATE:
I will like to give a special mention to my colleagues. Last but not the least I am
grateful to all the faculty members of Euphoria GenX or their support.
ABSTRACT
In today’s fast-changing business environment, it’s extremely important to be able
to respond to client needs in the most effective and timely manner. If your
customers wish to see your business online and have instant access to your
products or services. E-commerce is fast gaining ground as an accepted and used
business paradigm. More and more business houses are implementing web sites
providing functionality for performing commercial transactions over the web. It is
reasonable to say that the process of shopping on the web is becoming
commonplace. These types of online shops have become part of our daily lives. It
helps organizations to reduce the cost to create process, distribute, retrieve and
manage the paper-based information by digitalizing the information. The general
purpose of E-Commerce store where products can be bought from the comfort of
home through the Internet.
v
TABLE OF CONTENTS
LIST OF FIGURES ix
1 INTRODUCTION 1
1.1 OVERVIEW 1
2 LITERATURE SURVEY 2
vi
4.2.1 HOME PAGE 12
4.2.2 REGISTER PAGE 12
4.2.3 LOGIN PAGE 12
4.2.4 PRODUCT VIEW PAGE 12
4.2.5 CART PAGE 12
4.2.6 CHANGE PASSWORD PAGE 12
4.2.7 CONTACT US PAGE 13
4.2.8 TRACK ORDER PAGE 13
4.3 SYSTEM ARCHITECTURE 13
4.4 USE CASE DIAGRAM 14
4.4.1 CUSTOMER SIDE 14
4.4.2 ADMIN SIDE 14
4.5 IMPLEMENTATION 15
4.5.1 CREATING THE VIRTUAL ENVIRONMENT 15
4.5.2 CREATING VARIOUS APPS 16
4.5.3 CREATING MODELS 16
4.5.4 CREATING A SUPERUSER 17
4.5.5 CREATING VIEWS FOR THE MODELS 17
4.5.6 HOW DOES DJANGO WORK? 18
4.6 APPLICATION FUNCTIONALITIES 19
4.6.1 USER CREATION 19
4.6.2 COOKIES 19
4.6.3 SEARCH FUNCTIONALITY 19
4.6.4 CART FUNCTIONALITY 20
4.6.5 ORDER FUNCTIONALITY 20
4.6.6 CHANGE PASSWORD FUNCTIONALITY 20
4.6.7 CONTACT US FUNCTIONALITY 21
4.7 TESTING 21
5 RESULTS AND PERFORMANCE ANALYSIS 22
5.1 ADMINISTRATION PANEL 22
5.2 HOME PAGE BEFORE LOGIN 22
5.3 HOME PAGE AFTER LOGIN 23
vii
6.1 CONCLUSION 25
6.2 FUTURE WORKS 25
REFERENCES 26
APPENDIX 28
A. SOURCE CODE 28
viii
LIST OF FIGURES
ix
CHAPTER – 1
1. INTRODUCTION
1
CHAPTER – 2
2. LITERATURE REVIEW
Author: Abdul Gaffar Khan; Volume 16, Issue 1, Version 1.0, Year 2016
2
requires more attention towards e-commerce security for reducing the fraudulent
activities. The advancement of Information and Communication technology has
brought a lot of changes in all spheres of daily life of human being. Ecommerce
has a lot of benefits which add value to customer’s satisfaction in terms of
customer convenience in any place and enables the company to gain more
competitive advantage over the other competitors. This study predicts some
challenges in an emerging economy.
Authors: Dr. Rajasekar.S and Sweta Agarwal, Vol. 6, Issue, 03, pp. 7253-7256,
March, 2016
3
4. Django Based Web Application to Empower Skilled People
4
CHAPTER – 3
The reason behind our motivation is the current trend of web application
integration and interactive features. The trends of online shopping came into
existence in the early 90's. Today, there are many online shopping system in place
but there are many problems such as hands on experience, fraud and security
concern, privacy, lack of full cost disclosure, product reviews and so on. Our
project is to look to the current problems and to present on one-stop-shopping
platform that is beneficial for both customers and sellers.
In our platform, the users can view various products, if they wish to buy any
then they have to register and then login to add that product inside their cart. The
users or customers can also read the reviews about a product posted by other
users before buying it.
The users can add how many products he/she wants to their shopping cart.
Then the users are able to set the quantity of each added product inside the cart.
Finally, while checkout the users can give their address and the mode of payment
and place the respective order. Then the admin can see the customer details with
his/her order details and the address where the order should be delivered.
Here the Admin can upload their product details in website and the
customers can visit the Home Page and check whether the product is available
or not. Any
5
member can register and view available products. Only registered member can
purchase multiple products regardless of quantity.
The customers can add or view reviews about the products. The customers
can add different products to cart and can change the quantity. To place the order,
the customer can proceed checkout where they enter the details like address,
contact number and selecting the mode of payment. After placing the order, the
customer will get an Order ID. With the Order ID, they can track the details of the
order in the Track Order Page. If the customer faces any difficulties or issues in the
website, a Contact Us page is available to contact Admin for queries and report the
problem
6
3.4 SOFTWARE USED
Python is open source. You can download it for free and use it in your
application. You can also read and modify the source code.
The Python framework also has modules and packages, which facilitates
code reusability.
It provides rich data types and easier to read syntax than any other
programming
languages
It is a platform independent scripted language with full access to operating
system API's
Compared to other programming languages, it allows more run-time flexibility
It includes the basic text manipulation facilities of Perl and Awk
A module in Python may have one or more classes and free functions
Libraries in Pythons are cross-platform compatible with Linux, Macintosh,
and Windows
For building large applications, Python can be compiled to byte-code
Python supports functional and structured programming as well as OOP
It supports interactive mode that allows interacting Testing and debugging
of snippets of code
In Python, since there is no compilation step, editing, debugging and testing
is fast.
7
3.4.3 Django Framework
3.4.5 HTML
8
3.4.6 CSS
Cascading Style Sheets (CSS) is a style sheet language used for describing
the presentation of a document written in a markup language. Although most often
used to set the Visual style of web pages and user interfaces written in HTML and
XHTML, the language can be applied to any XML document, including plain XML,
SVG and XUL, and is applicable to rendering in speech, or on other media. Along
with HTML and JavaScript, CSS is a cornerstone technology used by most
websites to create visually engaging webpages, user interfaces for web
applications, and user interfaces for many mobile applications. CSS is designed
primarily to enable the separation of presentation and content, including aspects
such as the layout, colors, and fonts. This separation can improve content
accessibility, provide more flexibility and control in the specification of presentation
characteristics, enable multiple HTML pages to share formatting by specifying the
relevant CSS in a separate .css file, and reduce complexity and repetition in the
structural content.
3.4.7 JavaScript
3.4.8 Bootstrap
9
3.5 APPLICATION DEVELOPMENT PLAFTORM
3.5.1 VS Code
10
CHAPTER – 4
The web site, designed as an online shopping center, is separated into two
parts: back end and front-end parts. This part provides facility for each store owner
to edit and modify information in his own store. Providing validation check for
member and store identification, the back-end system can securely protect users’
proprietary information. In addition, all page views employ session variables to
deter manually defined variables by users. Applying user friendly approach, and
focusing on web programming inexperience, the user can effortlessly manage his
back-end information. Inside the back end, users can control and view all store
information. Besides that, using content management design, the back-end part
encompasses with these modules: admin panel, home, register, login, product
view, cart, checkout, change password, contact us and track order
11
4.2 APPLICATION DESCRIPTION
In this page, all the products are displayed on the home screen with the
image, name and price of the products. Two buttons are also created, one is for
adding the item inside the cart and the other is to view the product. If the
customers are not logged in then they are not able to add the item inside their cart.
They can just see all the products. On the add to cart button, login to add the item
will be written. The customers can directly search for the product that they want on
the search option given on the navigation bar.
In this page, users can register themselves, in order to view the product
details and place an order.
After clicking on the view button, the customers can view the specific
product with their key features and reviews. After reading the key features and the
reviews about the product, the customer can buy the product by clicking on the add
to cart button. The customer who has brought that specific product can write their
review about the product which the other customer is able to read.
By clicking on the shopping cart icon on the navigation bar, customers can
see all the added items in the cart. The users can then increase or decrease the
quantity of the products according to their requirements.
All the customers can change their password by going to the change
password option.
12
4.2.7 Contact Us page:
The customers can ask their queries or can contact us by filling a small
form. There are two different forms one for the logged in users and others who
haven’t registered themselves but want to contact us. If the user is a logged in
user, then the user just, have to write the message directly else the user needs to
first give his name, email and phone before contacting.
After placing the required order, you will get an order id. That id can be
further used for tracking the order. In the track order menu, you have to give your
order id for viewing the status of the order.
13
4.4 USE CASE DIAGRAM:
14
4.5 IMPLEMENTATION
After python has been installed on the pc, a virtual environment module
needs to be installed on the pc through python’s package manager. The virtual
environment makes it easy to run different versions of Django in isolation without
interrupting the process of one another. The Django module is installed in the
virtual environment along with some other modules that are needed to develop the
application specifying their versions.
Create Normal Project: Open the IDE and create a normal project by
selecting File ->> New Project.
Install Django: Next, we will install the Django module from the terminal. We
will use PyCharm integrated terminal to do this task. One can also use cmd
on windows to install the module by running python -m pip install django
command
Check Installed Django version: To check the installed Django version, you
can run the python -m django -version command as shown below.
Create Django Project: When we execute django-admin startproject
command, then it will create a Django project inside the normal project
which we already have created here. django-admin startproject
OnlineShopping.
Run Default Django web server: Django internally provides a default
webserver where we can launch our applications. python manage.py
runserver command in terminal. By default, the server runs on port 8000.
Access the webserver at the highlighted URL.
15
Fig 4.5.1 Django Webserver
16
Product model: It saves the data of the product. The admin can add a new
product very easily using this model.
Feature model: The admin can select the product and write any features
about it. And all the features of that product will be visible to the users
when they view a specific product.
Review model: All the customers can write a review about a product
which the customers can read before buying it.
Order model: It stores the order details about the customer, mainly
the order id.
OrderItems model: It stores the order id of the customer from the
order model and the products with their quantity.
Checkout Details model: It stores mainly the exact address where the
order is to be delivered.
The Superuser is simply the admin of the site. The admin account needs to
be created from the command line through the Django-admin command. The
admin account must be created in order to manage the site with a higher privilege
than the users of the site. The admin has the privilege to create, retrieve, update,
and delete data content and users from the site through the admin site. All models
present in the models.py file must be registered in admin.py file in order to allow
the models to be visible for the admin.
After creating the models, we need to go to the admin panel to access the
created models. Hence, we need a superuser who can access the models from the
admin panel. The superuser can make any changes inside the models.
When the models have been successfully registered in the admin site,
creating views for users is another task needed to be accomplished. This refers to
the logical functionality between the request and response of the clients and
servers. There are two types of views:
17
Function-based views: A view function, or view for short, is simply a Python
function that takes a Web request and returns a Web response. This
response can be the HTML contents of a Web page, or a redirect, or a 404
error, or an XML document, or an image or anything. The view itself
contains whatever arbitrary logic is necessary to return that response. This
code can live anywhere you want, as long as it’s on your Python path. For
the sake of putting the code somewhere, the convention is to put views in a
file called views.py, placed in your project or application directory. The view
function returns an HTML page that includes the request of the user.
Class-Based views: Class-based views provide an alternative way to
implement views as Python objects instead of functions. These allow you to
structure your views and reuse code by harnessing inheritance and mixins.
They do not replace function-based views, but have certain differences and
advantages when compared to function-based views: Organization of code
related to specific HTTP methods (GET, POST, etc.) can be addressed by
separate methods instead of conditional branching. Object oriented
techniques such as mixins (multiple inheritance) can be used to factor code
into reusable components.
To truly appreciate Django, you will need to peek under the hood and see
the various moving parts inside. This can be both enlightening and overwhelming.
The numbered paths are as follows:
The browser sends the request (essentially, a string of bytes) to the web
server.
The web server hands over the request to a WSGI server (say, uWSGI) or
directly serves a file (say, a CSS file) from the filesystem.
Unlike a web server, WSGI servers can run Python applications. The
request populates a Python dictionary called environ and, optionally, passes
through several layers of middleware, ultimately reaching your Django
application.
18
URLconf contained in the urls.py of your application selects a view to
handle the request based on the requested URL. The request has turned
into HttpRequest (a Python object).
The selected view typically does one or more of the following things: It Talks
to a database via the models. It Renders HTML or any other formatted
response using templates. It Returns a plain text response (not shown). It
Raises an exception.
The Http Response object gets rendered into a string, as it leaves the
Django application.
A beautifully rendered web page is seen in your user's browser.
4.6.2 Cookies
Django provides a session framework that lets you store and retrieve data
on a per-site-visitor basis. Django abstracts the process of sending and receiving
cookies, by placing a session ID cookie on the client side, and storing all the
related data on the server side. So the data itself is not stored client side.
A common task for web applications is to search some data in the database
with user input. In a simple case, this could be filtering a list of objects by a
category. A more complex use case might require searching with weighting,
categorization,
19
highlighting, multiple languages, and so on. This document explains some of the
possible use cases and the tools you can use.
Django does not store raw (clear text) passwords on the user model, but only a
hash (see documentation of how passwords are managed for full details). Because
of this, do not attempt to manipulate the password attribute of the user directly.
This is why a helper function is used when creating a user. To change a user’s
password, you have several options: manage.py changepassword *username*
offers a method of changing a user’s password from the command line.
It prompts you to change the password of a given user which you must
enter twice.
If they both match, the new password will be changed immediately.
If you do not supply a user, the command will attempt to change the
password whose username matches the current system user.
20
4.6.7 Contact Us Functionality
4.7 TESTING
The customer can only view the products, if he has logged in as a user.
Without being a customer/user, he is unable to view any products which are shown
on the home page. Some quantity of products was added into the shopping cart,
and then I proceeded to checkout. After successful checkout, the cart became
empty. This indicates that the cart works appropriately as it should and the Order
ID is shown in a pop-up. The customer can manipulate his cart, such as updating
the cart or adding a product to cart. The search bar shows the results of the
product search. If the user didn’t type anything, a message will be displayed saying
that the user forgot to type.
21
CHAPTER – 5
The admin can add the product to the website, where he will give the
product name, product price and image, then save it and that product displayed in
the website. These product data are stored has tables in Django default database
SQLite.
The home page is displayed successfully with all the products, navigation
bar with search functionality and footer at the bottom. If you want to purchase you
have to login as a customer. If you don't have an account then click register. It will
redirect to register page is displayed successfully with user registration form fields
and an URL which directs them to login page. The login page is displayed
successfully in order to login users can type their username and password.
22
Fig 5.2 Home page with added products
After the user is logged in successfully, the cart will be displayed in the
navigation bar which indicates that they can now view the products and add the
products to the cart. The products selected by the user will be shown in the order
summary with quantity increase and decrease functionality. For further process,
checkout button is available. The checkout page is shown successfully with the
product summary which was finalized by the customer. Under this, checkout
details will be displayed with form fields required to make shipment and selection
of payment mode will be available. After the order is placed, a pop-up containing
the Order ID is displayed and then the user will be redirected to home page where
the cart becomes empty. In order to track the progress of the orders which was
placed by the customer, you can check the, in the Track order page by entering a
valid Order ID in the track order text field. If the user faces any problems or issues,
they can report that issues in the contact us page, which is available in the navbar.
After entering the message in the description form field, a pop-up is displayed
23
successfully which indicates that the message was submitted to the admin. To
report a problem or to ask any queries, login is not mandatory.
24
CHAPTER – 6
6.1 CONCLUSION
The user can search for a product interactively and the search engine refine
the products available based on the user's input. Then the user can view the full
specifications and select the products, the user can see the products in the cart
and proceeds to checkout where they enter the address details and select the
mode of payment. The administrator can verify the orders. However, the customer
can still look at their status of the orders in the Track us page using the order ID.
With this platform, more opportunities will be created for profit and
advancements for businesses, while creating more options for both the consumers
and sellers.
25
REFERENCES
[1] Carl Burch, Django, a web framework using Python: tutorial presentation,
Journal of Computing Sciences in Colleges, Volume: 25, Issue: 5, 2010, Page: 154
– 155.
[2] Sheetal Taneja; Pratibha Gupta R, Python as a tool for web server application
[3] Kavya S.L; Dr.Sarathambekai S, Python Libraries and Packages for Web
[5] Adamya Shyam; Nitin Mukesh, A Django Based Educational Resource Sharing
Website: Shreic, Journal of Scientific Research, Volume: 64, Issue: 1, 2020, Page:
238 – 252.
[7] Busari O.A; Adebisi O.A; AdeagaI.I; Oni A.A, Development of an Online Shop
26
[8] Roger Fournier, A Methodology for Client/Server and Web Application
[9] Patrick J. Lynch, Sarah Horton, Web Style Guide: Basic Design Principles for
[10] Ralph Grove, Web Based Application Development, Jones & Bartlett
Publishers, 2009.
27
APPENDIX
A. SOURCE CODE
MODELS.PY:
class Customer(models.Model):
user = models.OneToOneField(User,
on_delete=models.CASCADE) name =
models.CharField(max_length=100)
email = models.CharField(max_length=100)
return str(self.user)
class Product(models.Model):
name = models.CharField(max_length=100)
price = models.FloatField()
return self.name
28
class Feature(models.Model):
class Review(models.Model):
content = models.TextField()
datetime = models.DateTimeField(default=now)
class Order(models.Model):
date_ordered = models.DateTimeField(default=now)
complete = models.BooleanField(default=False)
return str(self.id)
@property
29
def get_cart_total(self):
orderitems = self.orderitem_set.all()
return total
@property
def get_cart_items(self):
orderitems = self.orderitem_set.all()
return total
class OrderItem(models.Model):
quantity = models.IntegerField(default=0)
date_added = models.DateTimeField(default=now)
return str(self.order)
@property
def get_total(self):
return total
30
class UpdateOrder(models.Model):
order_id = models.ForeignKey(Order,
on_delete=models.CASCADE) desc =
models.CharField(max_length=500)
date = models.DateField(default=now)
return str(self.order_id)
class CheckoutDetail(models.Model):
address = models.CharField(max_length=300)
city = models.CharField(max_length=100)
state = models.CharField(max_length=100)
zipcode =
models.CharField(max_length=100)
date_added = models.DateTimeField(default=now)
return self.address
31
class Contact(models.Model):
name = models.CharField(max_length=100)
32
email = models.CharField(max_length=50)
phone = models.CharField(max_length=10)
desc =
models.CharField(max_length=1000)
return self.name
VIEWS.PY:
import json
def index(request):
data = cartData(request)
items = data['items']
order = data['order']
cartItems = data['cartItems']
products = Product.objects.all()
data = cartData(request)
items = data['items']
order = data['order']
cartItems = data['cartItems']
try:
cart = json.loads(request.COOKIES['cart'])
except:
cart = {}
print('Cart:',
cart)
for i in cart:
try:
cartItems += cart[i]["quantity"]
product = Product.objects.get(id=i)
order["get_cart_total"] += total
order["get_cart_items"] += cart[i]["quantity"]
item = {
'product':{
'id':product.id,
34
'name':product.name,
'price':product.price,
'image':product.image,
},
'quantity':cart[i]["quantity"],
'get_total':total
items.append(item)
except:
pass
def checkout(request):
data = cartData(request)
items = data['items']
order = data['order']
cartItems = data['cartItems']
total = order.get_cart_total
if request.method == "POST":
address = request.POST['address']
city = request.POST['city']
state = request.POST['state']
zipcode = request.POST['zipcode']
phone_number = request.POST['phone_number']
payment = request.POST['payment']
35
shipping_adress = CheckoutDetail.objects.create(address=address, city=city,
phone_number=phone_number, state=state, zipcode=zipcode,
customer=request.user.customer, total_amount=total, order=order,
payment=payment)
shipping_adress.save()
if total == order.get_cart_total:
order.complete = True
order.save()
id = order.id
alert = True
def updateItem(request):
data = json.loads(request.body)
productID = data['productID']
action = data['action']
print('Action:', action)
print('productID:',
productID)
customer = request.user.customer
product = Product.objects.get(id=productID)
37
update_order, created =
UpdateOrder.objects.get_or_create(order_id=order, desc="Your Order is
Successfully Placed.")
if action == 'add':
orderItem.quantity = (orderItem.quantity + 1)
orderItem.quantity = (orderItem.quantity - 1)
orderItem.save()
update_order.save()
if orderItem.quantity <= 0:
orderItem.delete()
customer = request.user.customer
product = Product.objects.filter(id=myid).first()
feature = Feature.objects.filter(product=product)
reviews =
Review.objects.filter(product=product) data =
cartData(request)
items = data['items']
order = data['order']
cartItems = data['cartItems']
38
if request.method=="POST":
39
content = request.POST['content']
review.save()
return redirect(f"/product_view/{product.id}")
def search(request):
data = cartData(request)
items = data['items']
order = data['order']
cartItems = data['cartItems']
if request.method == "POST":
search = request.POST['search']
else:
def change_password(request):
if not request.user.is_authenticated:
return redirect('/login')
data = cartData(request)
items = data['items']
40
order = data['order']
cartItems = data['cartItems']
if request.method == "POST":
current_password = request.POST['current_password']
new_password = request.POST['new_password']
try:
u = User.objects.get(id=request.user.id)
if u.check_password(current_password):
u.set_password(new_password)
u.save()
alert = True
else:
currpasswrong = True
except:
pass
def contact(request):
if request.method=="POST":
name = request.POST['name']
email = request.POST['email']
phone =
request.POST['phone'] desc =
41
request.POST['desc']
42
contact = Contact(name=name, email=email, phone=phone, desc=desc)
contact.save()
alert = True
def loggedin_contact(request):
data = cartData(request)
items = data['items']
order = data['order']
cartItems = data['cartItems']
if request.method=="POST":
name = request.user
email =
request.user.email
phone = request.user.customer.phone_number
desc = request.POST['desc']
contact.save()
alert = True
def tracker(request):
if not request.user.is_authenticated:
return redirect('/login')
43
data = cartData(request)
items = data['items']
order = data['order']
cartItems = data['cartItems']
if request.method == "POST":
order_id =
request.POST['order_id']
order = Order.objects.filter(id=order_id).first()
order_items =
OrderItem.objects.filter(order=order)
update_order =
UpdateOrder.objects.filter(order_id=order_id)
print(update_order)
def register(request):
if request.user.is_authenticated:
return redirect("/")
else:
if request.method=="POST":
username = request.POST['username']
full_name=request.POST['full_name']
password1 = request.POST['password1']
44
password2 = request.POST['password2']
phone_number = request.POST['phone_number']
email = request.POST['email']
45
if password1 != password2:
alert = True
user =
User.objects.create_user(username=username,
password=password1, email=email)
user.save()
customers.save()
alert = True
def Login(request):
if request.user.is_authenticated:
return redirect("/")
else:
if request.method == "POST":
username = request.POST['username']
password = request.POST['password']
login(request, user)
return redirect("/")
46
else:
alert = True
def Logout(request):
logout(request)
alert = True
BASE.HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-
EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLA
SjC" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/90ccb65d9b.js"
crossorigin="anonymous"></script>
47
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?
family=Red+Hat+Display:wght@500&disp lay=swap" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
data-bs-target="#navbarSupportedContent" aria-
controls="navbarSupportedContent" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<li>
</li>
{% if request.user.is_authenticated %}
<li>
48
<a class="nav_links" href="/cart/"><span class="fa fa-shopping-
cart"></span>({{cartItems}})</a>
</li>
<li>
</li>
<li>
</li>
<li">
</li>
{% endif %}
{% if not request.user.is_authenticated %}
<li>
</li>
<li>
</li>
<li>
</li>
{% else %}
49
<a class="nav_links2" href="#">Welcome {{request.user}}</a>
{% endif %}
</ul>
</div>
</form>
</div>
</div>
</nav>
{% block body %}
{% endblock %}
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-
MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVX
M"
crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-
J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n
"
crossorigin="anonymous"></script>
50
<script>
function getToken(name)
{ cookieValue =
decodeURIComponent(cookie.substring(name.length + 1));
break;
return cookieValue;
function getCookie(name) {
51
var cookiePair = cookieArr[i].split("=");
if (name == cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[1]);
return null;
if (cart == undefined)
{ cart = {}
console.log('Cart:', cart)
{ updateBtns[i].addEventListener('click', function () {
52
var action = this.dataset.action
console.log('USER:', user)
if (user == 'AnonymousUser') {
addCookieItem(productID, action)
} else {
updateUserOrder(productID, action)
})
if (action == 'add') {
if (cart[productID] == undefined)
{ cart[productID] = { 'quantity': 1 }
} else {
cart[productID]['quantity'] += 1
['quantity'] -= 1
53
if (cart[productID]['quantity'] <= 0)
delete cart[productID];
console.log('Cart:', cart)
location.reload()
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrftoken,
},
})
.then((response) =>
{ return
response.json()
})
54
.then((data) =>
{ console.log('data:', data)
location.reload()
})
</script>
{% block js %}
{% endblock %}
</body>
</html>
INDEX.HTML:
{% extends 'base.html' %}
{% load static %}
{% block css %}
{% endblock %}
{% block body %}
<div class="row">
55
{% for product in products %}
<h5 class="name-h5">{{product.name}}</h5>
<h4 class="name-h4"> ₹{{product.price}}</h4>
</div>
</div>
{% if request.user.is_authenticated %}
{% else %}
{% endif %}
</div>
</div>
</div>
{% endfor %}
</div>
</div>
56
<footer class="footer-distributed">
<div class="footer-left">
</div>
<div class="footer-center">
<div>
</div>
<div>
<p>+91 45-86321459</p>
</div>
<div>
<p><a href="mailto:[email protected]"
style="color:#e668ff;">[email protected]</a></p>
</div>
57
</div>
<div class="footer-right">
<p class="footer-company-about">
<ul class="icon-container">
<li class="icon-list">
</a>
</li>
<li class="icon-list">
</a>
</li>
<li class="icon-list">
</a>
</li>
<li class="icon-list">
</a>
</li>
58
</ul>
</span>
</div>
</footer>
{% endblock %}
{% block js %}
<script>
{% if alert %}
alert("Logout
Successful.")
window.location.href = '/'
{% endif %}
</script>
{% endblock %}
59