ShopKart Online Shopping Template
ShopKart Online Shopping Template
STATIC/CSS/[Link]
@import url('[Link]
family=Noto+Sans:wght@300;400;500;700&display=swap');
html {
font-size: 14px;
}
body {
font-family: 'Noto Sans', sans-serif;
}
a {
text-decoration: none;
}
.carousel-item img {
object-fit: cover;
object-position: top;
height: 60vh;
overflow: hidden;
}
.old_price {
font-weight: bold;
color: red;
}
.new_price {
font-weight: bold;
background-color: green;
color: white;
padding: 2px;
border-radius: 5px;
margin-bottom: 2px;
}
.pic-box {
position: relative;
}
.hot {
background-color: orangered;
color: white;
width: 50px;
text-align: center;
font-weight: bold;
display: inline;
border-radius: 5px;
padding: 5px;
position: absolute;
top: 0;
right: 20px;
z-index: 10;
}
Included files
SHOP/TEMPLATES/SHOP/LAYOUTS/[Link]
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link
href="[Link]
" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOm
LASjC" crossorigin="anonymous">
<title>
{% block title %}
{% endblock title %}
</title>
<link rel="stylesheet"
href="[Link]
[Link]">
<link rel="stylesheet" href="{% static 'css/[Link]' %}">
</head>
<body>
{% include 'shop/inc/[Link]' %}
{% block content %}
{% endblock content %}
{% block scripts %}
{% endblock scripts %}
{% include 'shop/inc/[Link]' %}
<script
src="[Link]
[Link]" integrity="sha384-
MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</body>
</html>
SHOP/TEMPLATES/SHOP/INC/[Link]
{% for msg in messages %}
<div class="alert alert-info alert-dismissible fade show" role="alert">
{{msg}}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-
label="Close"></button>
</div>
{% endfor %}
SHOP/TEMPLATES/SHOP/INC/[Link]
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="{% url 'home' %}"><i class="fa fa-cart-
plus"></i> ShopKart</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-
expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav ms-auto">
<a class="nav-link" aria-current="page" href="{% url 'home' %}"><i
class="fa fa-home"></i> Home</a>
{% if [Link].is_authenticated %}
<a class="nav-link" aria-current="page" href="#"><i class="fa fa-
user"></i> {{[Link]}}</a>
<a class="nav-link" aria-current="page" href="{% url 'logout'
%}"><i class="fa fa-sign-out"></i> Logout</a>
{% else %}
<a class="nav-link" href="{% url 'login' %}"><i class="fa fa-sign-
in"></i> Login</a>
<a class="nav-link" href="{% url 'register' %}"><i class="fa fa-
users"></i> Register</a>
{% endif %}
<a class="nav-link" href="{% url 'collections' %}"><i class="fa fa-
cubes"></i> Collections</a>
<a class="nav-link" href="{% url 'cart' %}"><i class="fa fa-
shopping-cart"></i> Cart</a>
<a class="nav-link" href="{% url 'favviewpage' %}"><i class="fa fa-
heart"></i> Favourite</a>
</div>
</div>
</div>
</nav>
SHOP/TEMPLATES/SHOP/INC/[Link]
{% load static %}
<div id="carouselExampleIndicators" class="carousel slide" data-bs-
ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleIndicators" data-
bs-slide-to="0" class="active" aria-current="true" aria-label="Slide
1"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-
bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-
bs-slide-to="2" aria-label="Slide 3"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-
bs-slide-to="3" aria-label="Slide 4"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="{% static 'images/[Link]' %}" class="d-block w-100" alt="Slide
1">
</div>
<div class="carousel-item">
<img src="{% static 'images/[Link]' %}" class="d-block w-100" alt="Slide
2">
</div>
<div class="carousel-item">
<img src="{% static 'images/[Link]' %}" class="d-block w-100" alt="Slide
3">
</div>
<div class="carousel-item">
<img src="{% static 'images/[Link]' %}" class="d-block w-100" alt="Slide
4">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-
target="#carouselExampleIndicators" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-
target="#carouselExampleIndicators" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
SHOP/TEMPLATES/SHOP/INC/[Link]
<footer class="text-center text-lg-start bg-dark text-white">
<section class="container d-flex justify-content-center justify-content-
lg-between p-4">
<div class="me-5 d-none d-lg-block">
<span>Get connected with us on social networks:</span>
</div>
<div>
<a href="" class="me-4 text-reset"><i class="fa fa-facebook"></i></a>
<a href="" class="me-4 text-reset"><i class="fa fa-twitter"></i></a>
<a href="" class="me-4 text-reset"><i class="fa fa-google"></i></a>
<a href="" class="me-4 text-reset"><i class="fa fa-
instagram"></i></a>
<a href="" class="me-4 text-reset"><i class="fa fa-linkedin"></i></a>
<a href="" class="me-4 text-reset"><i class="fa fa-github"></i></a>
</div>
</section>
<section class="">
<div class="container text-center text-md-start mt-5">
<div class="row mt-3">
<div class="col-md-3 col-lg-4 col-xl-3 mx-auto mb-4">
<h6 class="text-uppercase fw-bold mb-4"><i class="fa fa-cart-
plus"></i> ShopKart</h6>
<p>
[Link] is a one stop destination for your family's
fashion needs.
We give you the opportunity to give your wardrobe a makeover
with the latest collections from our top brands.
</p>
</div>
</div>
</div>
</section>
<div class="text-center p-4">
© 2021 Copyright <a class="text-reset fw-bold"
href="[Link] /"> [Link]</a>
</div>
</footer>
SHOP/TEMPLATES/SHOP/[Link]
{% extends 'shop/layouts/[Link]' %}
{% block title %}
ShopKart | Online Shopping
{% endblock title %}
{% block content %}
{% include 'shop/inc/[Link]' %}
<div class="container" style="margin-top:70px;" >
<div class="row">
<div class="col-12">
<h4 class="mb-3"> Latest Offfers</h4>
<hr style="border-color:#b8bfc2;">
</div>
{% for item in products %}
<div class="col-md-4 col-lg-3">
<div class="card my-3">
<img src="{{item.product_image.url}}" class="card-image-top"
alt="Categories">
<a href="{% url 'product_details' [Link] [Link] %}">
<div class="card-body">
<h5 class="card-title text-primary">{{ [Link] }}</h5>
<p class="card-text">
<span class="float-start old_price"><s>Rs.
{{ item.original_price | stringformat:'d'}}</s></span>
<span class="float-end new_price">Rs.{{ item.selling_price |
stringformat:'d' }}</span>
</p>
</div>
</a>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock content %}
SHOP/TEMPLATES/SHOP/[Link]
{% extends 'shop/layouts/[Link]' %}
{% block title %}
Registration | ShopKart
{% endblock title %}
{% block content %}
<div class="container" style="margin-top:70px;min-height:600px;">
<div class="row">
<div class="col-12">
<h4 class="mb-3"> New User Registration</h4>
<hr style="border-color:#b8bfc2;">
{% include 'shop/inc/[Link]' %}
</div>
</div>
<section class="py-4" >
<div class="container">
<div class="row">
<div class="col-6">
<form method="post" action="">
{% csrf_token %}
<div class="mb-4">
<label for="" class="form-label">User Name</label>
{{[Link]}}
</div>
<div class="mb-4">
<label for="" class="form-label">User Email</label>
{{[Link]}}
</div>
<div class="mb-4">
<label for="" class="form-label">Password</label>
{{form.password1}}
</div>
<div class="mb-4">
<label for="" class="form-label">Confirm Password</label>
{{form.password2}}
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
<p class="my-2">Already user ? <a href="{% url 'login' %}">Login
Now</a> </p>
</div>
<div class="col-6">
{% if [Link] %}
<label class="text-danger d-
block">{{ [Link] }}</label>
{% endif %}
{% if [Link] %}
<label class="text-danger d-
block">{{ [Link] }}</label>
{% endif %}
{% if [Link].password1 %}
<label class="text-danger d-
block">{{ [Link].password1 }}</label>
{% endif %}
{% if [Link].password2 %}
<label class="text-danger d-
block">{{ [Link].password2 }}</label>
{% endif %}
</div>
</div>
</div>
</section>
</div>
{% endblock content %}
SHOP/TEMPLATES/SHOP/[Link]
{% extends 'shop/layouts/[Link]' %}
{% block title %}
Registration | ShopKart
{% endblock title %}
{% block content %}
<div class="container" style="margin-top:70px;min-height:600px;">
<div class="row">
<div class="col-12">
<h4 class="mb-3"> User Login</h4>
<hr style="border-color:#b8bfc2;">
{% include 'shop/inc/[Link]' %}
</div>
</div>
<section class="py-4" >
<div class="container">
<div class="row">
<div class="col-6">
<form method="post" action="">
{% csrf_token %}
<div class="mb-4">
<label for="" class="form-label">User Name</label>
<input type="text" name="username" id="username" class="form-
control" placeholder="Enter User Name">
</div>
<div class="mb-4">
<label for="" class="form-label">Password</label>
<input type="password" name="password" id="password"
class="form-control" placeholder="Enter Password">
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
</div>
</div>
</section>
</div>
{% endblock content %}
SHOP/TEMPLATES/SHOP/[Link]
{% extends 'shop/layouts/[Link]' %}
{% block title %}
Registration | ShopKart
{% endblock title %}
{% block content %}
<section class="py-5 text-center container" style="margin-top:70px;">
<div class="row py-lg-5">
<div class="col-lg-6 col-md-8 mx-auto">
<h1 class="fw-light">Bestsellers</h1>
<p class="lead text-muted">Our most popular products based on sales.
Updated hourly.</p>
<p>
<a href="{% url 'login' %}" class="btn btn-primary my-2">Already
User</a>
<a href="{% url 'register' %}" class="btn btn-secondary my-
2">Register</a>
</p>
</div>
</div>
</section>
<section class="bg-light py-4 my-5" style="min-height:600px;">
<div class="container">
<div class="row">
<div class="col-12">
<h4 class="mb-3">Categories</h4>
<hr style="border-color:#b8bfc2;">
{% include 'shop/inc/[Link]' %}
</div>
{% for item in catagory %}
<div class="col-md-4 col-lg-3">
<div class="card my-3">
<img src="{{[Link]}}" class="card-image-top"
alt="Categories">
<a href="{% url 'collections' [Link] %}">
<div class="card-body">
<h5 class="card-title text-primary">{{ [Link] }}</h5>
<p class="card-text">{{ [Link] }}</p>
</div>
</a>
</div>
</div>
{% endfor %}
</div>
</div>
</section>
{% endblock content %}
SHOP/TEMPLATES/SHOP/[Link]
{% extends 'shop/layouts/[Link]' %}
{% block title %}
Registration | ShopKart
{% endblock title %}
{% block content %}
<section class="bg-light py-4 my-5" style="min-height:600px;">
<div class="container">
<div class="row">
<div class="col-12">
<h4 class="mb-3">Favourite Item</h4>
<hr style="border-color:#b8bfc2;">
</div>
<table>
<tr>
<th>Image</th>
<th>Product Name</th>
<th>Unit</th>
<th>Remove</th>
</tr>
</div>
</div>
</section>
{% endblock content %}
SHOP/TEMPLATES/SHOP/[Link]
{% extends 'shop/layouts/[Link]' %}
{% block title %}
Registration | ShopKart
{% endblock title %}
{% block content %}
<section class="bg-light py-4 my-5" style="min-height:600px;">
<div class="container">
<div class="row">
<div class="col-12">
<h4 class="mb-3">Cart Items</h4>
<hr style="border-color:#b8bfc2;">
</div>
<table>
<tr>
<th>Image</th>
<th>Product Name</th>
<th>Unit</th>
<th>Quantity</th>
<th>Amount</th>
<th>Remove</th>
</tr>
</table>
</div>
</div>
</section>
<script>
const nodes = [Link]('.amt');
const arr = [Link](nodes);
const res = [Link]((acc, curr) => {
return acc += Number([Link])
}, 0);
[Link]("net").innerHTML="Rs : "+res;
</script>
{% endblock content %}
TEMPLATES/SHOP/PRODUCTS/[Link]
{% extends 'shop/layouts/[Link]' %}
{% block title %}
ShopKart | Online Shopping
{% endblock title %}
{% block content %}
<section class="bg-light py-4 my-5" style="min-height:600px;">
<div class="container">
<div class="row">
<div class="col-12">
<h4 class="mb-3">{{category_name}} Products</h4>
<hr style="border-color:#b8bfc2;">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{% url 'home'
%}">Home</a></li>
<li class="breadcrumb-item active">{{category_name}}
Collections</li>
</ol>
</nav>
{% include 'shop/inc/[Link]' %}
</div>
{% for item in products %}
<div class="col-md-4 col-lg-3">
<div class="card my-3">
<img src="{{item.product_image.url}}" class="card-image-top"
alt="Categories">
<a href="{% url 'product_details' category_name [Link] %}">
<div class="card-body">
<h5 class="card-title text-primary">{{ [Link] }}</h5>
<p class="card-text">
<span class="float-start old_price"><s>Rs.
{{ item.original_price | stringformat:'d'}}</s></span>
<span class="float-end new_price">Rs.{{ item.selling_price |
stringformat:'d' }}</span>
</p>
</div>
</a>
</div>
</div>
{% endfor %}
</div>
</div>
</section>
{% endblock content %}
TEMPLATES/SHOP/PRODUCTS/PRODUCT_DETAILS.HTML
{% extends 'shop/layouts/[Link]' %}
{% block title %}
ShopKart | Online Shopping
{% endblock title %}
{% block content %}
<section class="bg-light py-4 my-5" style="min-height:600px;">
<div class="container">
<div class="row">
<div class="col-12">
<h4 class="mb-3"> {{products}} Details</h4>
<hr style="border-color:#b8bfc2;">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{% url 'home'
%}">Home</a></li>
<li class="breadcrumb-item"><a href="{% url 'collections'
[Link] %}">Collections</a></li>
<li class="breadcrumb-item active" aria-
current="page">{{products}}</li>
</ol>
</nav>
{% include 'shop/inc/[Link]' %}
</div>
<div class="col-4 my-3 pic-box">
{% if [Link] %}
<div class="hot">Hot</div>
{% endif %}
<img src="{{products.product_image.url}}" class="card-image-top"
alt="{{products}}">
</div>
<div class="col-8 my-3">
<h5 class="text-success">{{products | upper}}</h5>
<p>{{[Link]}}</p>
<p>{{[Link]}}</p>
<h6 class="my-2 text-danger">Current Price : Rs.
<s>{{products.original_price}}</s></h6>
<h5 class="my-2 text-primary">Offer Price : Rs.
{{products.selling_price}}</h5>
<div class="my-3">
{% if [Link] > 0 %}
<input type="hidden" value="{{[Link]}}" id="pid">
<p>
<div class="input-group" style="width:150px">
<button class="input-group-text bg-success text-light"
id="btnMinus" ><i class="fa fa-minus"></i></button>
<input type="text" name="qty" id="txtQty" value="1"
class="form-control text-center">
<button class="input-group-text bg-success text-light"
id="btnPlus"><i class="fa fa-plus"></i></button>
</div>
</p>
<button class="btn btn-primary" id="btnCart"><i class="fa fa-
shopping-cart"></i> Add to Cart</button>
{% else %}
<button class="btn btn-secondary"><i class="fa fa-minus"></i> Out
of Stock</button>
{% endif %}
<button class="btn btn-danger" id="btnFav"><i class="fa fa-
heart"></i></button>
</div>
</div>
</div>
</div>
</section>
<script>
[Link]("DOMContentLoaded", function(event) {
const btnPlus = [Link]("btnPlus");
const btnMinus = [Link]("btnMinus");
const txtQty = [Link]("txtQty");
const pid = [Link]("pid");
const btnCart = [Link]("btnCart");
const btnFav = [Link]("btnFav");
[Link]("click", function() {
let qty=parseInt([Link],10);
qty=isNaN(qty)?0:qty;
//[Link](qty);
if(qty<10){
qty++;
[Link]=qty;
}
});
[Link]("click", function() {
let qty=parseInt([Link],10);
qty=isNaN(qty)?0:qty;
//[Link](qty);
if(qty>1){
qty--;
[Link]=qty;
}
});
[Link]("click", function() {
let qty=parseInt([Link],10);
qty=isNaN(qty)?0:qty;
if(qty>0){
let postObj = {
'product_qty': qty,
'pid': [Link]
}
//[Link](postObj);
fetch("/addtocart",{
method: 'POST',
credentials: 'same-origin',
headers:{
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRFToken': '{{ csrf_token }}',
},
body: [Link](postObj)
}).then(response => {
return [Link]();
}).then(data => {
//[Link](data);
alert(data['status']);
});
}else{
alert("Please Enter The Quantity");
}
});
[Link]("click", function() {
let postObj = {
'pid': [Link]
}
[Link](postObj);
fetch("/fav",{
method: 'POST',
credentials: 'same-origin',
headers:{
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRFToken': '{{ csrf_token }}',
},
body: [Link](postObj)
}).then(response => {
return [Link]();
}).then(data => {
//[Link](data);
alert(data['status']);
});
});
});
</script>
{% endblock content %}
Python Files
shop/[Link]
from atexit import register
from [Link] import admin
from .models import *
"""
class CategoryAdmin([Link]):
list_display = ('name', 'image', 'description')
[Link](Catagory,CategoryAdmin)
"""
[Link](Catagory)
[Link](Product)
[Link](Cart)
[Link](Favourite)
shop/[Link]
from [Link] import AppConfig
class ShopConfig(AppConfig):
default_auto_field = '[Link]'
name = 'shop'
shop/[Link]
from pyexpat import model
from [Link] import UserCreationForm
from .models import User
from django import forms
class CustomUserForm(UserCreationForm):
username=[Link](widget=[Link](attrs={'class':'form-
control','placeholder':'Enter User Name'}))
email=[Link](widget=[Link](attrs={'class':'form-
control','placeholder':'Enter Email Address'}))
password1=[Link](widget=[Link](attrs={'class':'form-
control','placeholder':'Enter Your Password'}))
password2=[Link](widget=[Link](attrs={'class':'form-
control','placeholder':'Enter Confirm Password'}))
class Meta:
model=User
fields=['username','email','password1','password2']
shop/[Link]
from itertools import product
from [Link] import models
from [Link] import User
import datetime
import os
def getFileName(requset,filename):
now_time=[Link]().strftime("%Y%m%d%H:%M:%S")
new_filename="%s%s"%(now_time,filename)
return [Link]('uploads/',new_filename)
class Catagory([Link]):
name=[Link](max_length=150,null=False,blank=False)
image=[Link](upload_to=getFileName,null=True,blank=True)
description=[Link](max_length=500,null=False,blank=False)
status=[Link](default=False,help_text="0-show,1-Hidden")
created_at=[Link](auto_now_add=True)
def __str__(self) :
return [Link]
class Product([Link]):
category=[Link](Catagory,on_delete=[Link])
name=[Link](max_length=150,null=False,blank=False)
vendor=[Link](max_length=150,null=False,blank=False)
product_image=[Link](upload_to=getFileName,null=True,blank=True)
quantity=[Link](null=False,blank=False)
original_price=[Link](null=False,blank=False)
selling_price=[Link](null=False,blank=False)
description=[Link](max_length=500,null=False,blank=False)
status=[Link](default=False,help_text="0-show,1-Hidden")
trending=[Link](default=False,help_text="0-default,1-Trending")
created_at=[Link](auto_now_add=True)
def __str__(self) :
return [Link]
class Cart([Link]):
user=[Link](User,on_delete=[Link])
product=[Link](Product,on_delete=[Link])
product_qty=[Link](null=False,blank=False)
created_at=[Link](auto_now_add=True)
@property
def total_cost(self):
return self.product_qty*[Link].selling_price
class Favourite([Link]):
user=[Link](User,on_delete=[Link])
product=[Link](Product,on_delete=[Link])
created_at=[Link](auto_now_add=True)
shop/[Link]
from [Link] import path
from . import views
urlpatterns= [
path('',[Link],name="home"),
path('register',[Link],name="register"),
path('login',views.login_page,name="login"),
path('logout',views.logout_page,name="logout"),
path('cart',views.cart_page,name="cart"),
path('fav',views.fav_page,name="fav"),
path('favviewpage',[Link],name="favviewpage"),
path('remove_fav/<str:fid>',views.remove_fav,name="remove_fav"),
path('remove_cart/<str:cid>',views.remove_cart,name="remove_cart"),
path('collections',[Link],name="collections"),
path('collections/<str:name>',[Link],name="collections"),
path('collections/<str:cname>/<str:pname>',views.product_details,name="product
_details"),
path('addtocart',views.add_to_cart,name="addtocart"),
]
shop/[Link]
from [Link] import JsonResponse
from [Link] import redirect, render
from [Link] import CustomUserForm
from . models import *
from [Link] import messages
from [Link] import authenticate,login,logout
import json
def home(request):
products=[Link](trending=1)
return render(request,"shop/[Link]",{"products":products})
def favviewpage(request):
if [Link].is_authenticated:
fav=[Link](user=[Link])
return render(request,"shop/[Link]",{"fav":fav})
else:
return redirect("/")
def remove_fav(request,fid):
item=[Link](id=fid)
[Link]()
return redirect("/favviewpage")
def cart_page(request):
if [Link].is_authenticated:
cart=[Link](user=[Link])
return render(request,"shop/[Link]",{"cart":cart})
else:
return redirect("/")
def remove_cart(request,cid):
cartitem=[Link](id=cid)
[Link]()
return redirect("/cart")
def fav_page(request):
if [Link]('x-requested-with')=='XMLHttpRequest':
if [Link].is_authenticated:
data=[Link](request)
product_id=data['pid']
product_status=[Link](id=product_id)
if product_status:
if
[Link](user=[Link],product_id=product_id):
return JsonResponse({'status':'Product Already in Favourite'},
status=200)
else:
[Link](user=[Link],product_id=product_id)
return JsonResponse({'status':'Product Added to Favourite'},
status=200)
else:
return JsonResponse({'status':'Login to Add Favourite'}, status=200)
else:
return JsonResponse({'status':'Invalid Access'}, status=200)
def add_to_cart(request):
if [Link]('x-requested-with')=='XMLHttpRequest':
if [Link].is_authenticated:
data=[Link](request)
product_qty=data['product_qty']
product_id=data['pid']
#print([Link])
product_status=[Link](id=product_id)
if product_status:
if [Link](user=[Link],product_id=product_id):
return JsonResponse({'status':'Product Already in Cart'},
status=200)
else:
if product_status.quantity>=product_qty:
[Link](user=[Link],product_id=product_id,product_qty=produc
t_qty)
return JsonResponse({'status':'Product Added to Cart'},
status=200)
else:
return JsonResponse({'status':'Product Stock Not Available'},
status=200)
else:
return JsonResponse({'status':'Login to Add Cart'}, status=200)
else:
return JsonResponse({'status':'Invalid Access'}, status=200)
def logout_page(request):
if [Link].is_authenticated:
logout(request)
[Link](request,"Logged out Successfully")
return redirect("/")
def login_page(request):
if [Link].is_authenticated:
return redirect("/")
else:
if [Link]=='POST':
name=[Link]('username')
pwd=[Link]('password')
user=authenticate(request,username=name,password=pwd)
if user is not None:
login(request,user)
[Link](request,"Logged in Successfully")
return redirect("/")
else:
[Link](request,"Invalid User Name or Password")
return redirect("/login")
return render(request,"shop/[Link]")
def register(request):
form=CustomUserForm()
if [Link]=='POST':
form=CustomUserForm([Link])
if form.is_valid():
[Link]()
[Link](request,"Registration Success You can Login Now..!")
return redirect('/login')
return render(request,"shop/[Link]",{'form':form})
def collections(request):
catagory=[Link](status=0)
return render(request,"shop/[Link]",{"catagory":catagory})
def collectionsview(request,name):
if([Link](name=name,status=0)):
products=[Link](category__name=name)
return render(request,"shop/products/[Link]",
{"products":products,"category_name":name})
else:
[Link](request,"No Such Catagory Found")
return redirect('collections')
def product_details(request,cname,pname):
if([Link](name=cname,status=0)):
if([Link](name=pname,status=0)):
products=[Link](name=pname,status=0).first()
return render(request,"shop/products/product_details.html",
{"products":products})
else:
[Link](request,"No Such Produtct Found")
return redirect('collections')
else:
[Link](request,"No Such Catagory Found")
return redirect('collections')
lak_project/[Link]
"""lak_project URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
[Link]
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', [Link], name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from [Link] import include, path
2. Add a URL to urlpatterns: path('blog/', include('[Link]'))
"""
if [Link]:
urlpatterns+=static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
lak_project/[Link]
"""
Django settings for lak_project project.
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'jazzmin',
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'shop'
]
MIDDLEWARE = [
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'[Link]',
]
ROOT_URLCONF = 'lak_project.urls'
TEMPLATES = [
{
'BACKEND': '[Link]',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'[Link].context_processors.debug',
'[Link].context_processors.request',
'[Link].context_processors.auth',
'[Link].context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'lak_project.[Link]'
# Database
# [Link]
DATABASES = {
'default': {
'ENGINE': '[Link]',
'NAME': 'django_lak',
'HOST':'localhost',
'USER':'root',
'PASSWORD':'root',
'PORT':'3306'
}
}
# Password validation
# [Link]
validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME':
'[Link].password_validation.UserAttributeSimilarityValidator',
},
{
'NAME':
'[Link].password_validation.MinimumLengthValidator',
},
{
'NAME':
'[Link].password_validation.CommonPasswordValidator',
},
{
'NAME':
'[Link].password_validation.NumericPasswordValidator',
},
]
# Internationalization
# [Link]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
STATIC_URL = 'static/'
MEDIA_URL='/images/'
MEDIA_ROOT=BASE_DIR/'static'
STATICFILES_DIRS=[
BASE_DIR/'static'
]
DEFAULT_AUTO_FIELD = '[Link]'