Return render(request,'website/home.html',context)įorm=createorderform(request.POST,instance=customer) Urlpatterns+=static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)Ĭode: from django.shortcuts import redirect,renderįrom import login,logout,authenticate Path('addProduct/', addProduct,name='addProduct'), Path('register/', registerPage,name='register'), Path('logout/', logoutPage,name='logout'), Path('placeOrder//',placeOrder,name='placeOrder'), Add a URL to urlpatterns: path('blog/', include('blog.urls'))įrom import static Import the include() function: from django.urls import include, pathĢ. Add a URL to urlpatterns: path('', Home.as_view(), name='home')ġ. Add an import: from other_app.views import HomeĢ. Add a URL to urlpatterns: path('',, name='home')ġ. Add an import: from my_app import viewsĢ. The `urlpatterns` list routes URLs to views. So, your urls.py should contain the following code.Ĭode: """OnlineShopping URL Configuration In this file also we need to specify a static folder path.
#Django web development code
Append the below code in settings.py import os
#Django web development update
settings.pyĪs we are using images in our project we have to update the static path settings in the setting.py file. Enter your name, email and password to create the same. Now we need a user to access the admin panel, therefore we will create a superuser. We have written this code to register the models on the admin panel. To implement the crud functionality i.e for creating, updating or deleting entries from the database, we are creating these forms. To apply the database changes, run the following Py manage.py makemigrationsįrom import UserCreationForm Order: This model stores order related details like buyer’s information, product’s information, date ordered, and the status of the order (pending, packed, delivered, canceled, etc).Customer: Model stores customer details.Product: This model stores product details like image, name, description.We have created three models in this file. We have used Django’s default database i.e. Status = models.CharField(max_length=20,default= 'PENDING') Product = models.ForeignKey( Product,null=True, on_delete=models.SET_NULL)Ĭustomer = models.ForeignKey(Customer,null=True, on_delete=models.SET_NULL)ĭate_ordered = models.DateTimeField(auto_now_add=True) Image = models.ImageField(null=True,blank=True)ĭescription = models.CharField(max_length=400,null=True) User = models.OneToOneField(User, null=True, on_delete=models.CASCADE)ĭate_created = models.DateTimeField(auto_now_add=True) Name = models.CharField(max_length=200,null=True) Commands to start the project and app django-admin startproject OnlineShoppingĭjango-admin startapp website 2. Starting project:įirst of all, we have to create a project and an app. Let’s create an ecommerce website with python django 1. Please download the source code of python e-commerce website: Ecommerce Website Python Code Steps to Create an Ecommerce website with Python Django
#Django web development install
To install Django, you can use the pip installer from cmd/terminal. Django framework: web development framework.Bootstrap: html, css, and javascript framework used to build responsive websites.It sounds complex but it’s actually not, we can create an e-commerce website very easily using python django.ĭjango is an open-source python framework, which is widely used to create web development projects because of its inbuilt functionalities and rapid development. Did you ever wonder if we can develop one on our own? E-commerce is now part of our daily life, we use e-commerce websites to order anything and everything.