Sunday, August 1, 2021

django - Creating E-commerce website with apps setups

Here, We will be creating a django E-commerce project named "myEcommerceSite" with 2 apps named "shop" and "blog" within it.

Django Apps :

  • Apps in Django are pluggable web applications.
  • Django apps are the self-sufficient sub module of a project. A project can contain more than one apps, and an app can be used in more than one project.

Follow the below steps:

Step 1: Click on File and then select New Project.

Step 2: After clicking on New Project, a pop-up window will appear. Select the location(PycharmProjects folder recommended) and name the file as myEcommerceSite

Step3: Start the project

C:\Users\Srinanda\Desktop\python\djangoCodeSource\myEcommerceSite>django-admin startproject mes

Step 4: Run the command in following format to create the app.

python manage.py startapp name_of_the_app

C:\Users\Srinanda\Desktop\python\djangoCodeSource\myEcommerceSite\mes>python manage.py startapp blog

C:\Users\Srinanda\Desktop\python\djangoCodeSource\myEcommerceSite\mes>python manage.py startapp shop

The project looks like :


Step5: Create urls.py file in both apps.

shop\urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name="ShopHome"),
]
blog\urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name="blogHome"),
]

Step6: create views.py as below:

shop\views.py:
from django.shortcuts import render
from django.http import HttpResponse

def index(request):
return HttpResponse("index shop")


blog\view.py:
from django.shortcuts import render
from django.http import HttpResponse

def index(request):
return HttpResponse("index blog")


Step7: Update the main "mes" project urls.py with the following to include blog and shop apps urls.py

from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('shop/', include('shop.urls')),
path('blog/', include('blog.urls'))
]

Step8: run server:
C:\Users\Srinanda\Desktop\python\djangoCodeSource\myEcommerceSite\mes>python manage.py runserver

Step9: open following urls and  test:
http://127.0.0.1:8000/blog/ 
http://127.0.0.1:8000/shop/



No comments:

Post a Comment

Featured Post

OIC - Restrictions on Using Stage File Action Operations with the File/Attachment Features of the Connectivity Agent

Restrictions on Using Stage File Action Operations with the File/Attachment Features of the Connectivity Agent When configuring the stage fi...