Django Installation

To Install Django in Linux and Mac is similar, here I am showing it in Windows for Linux and Mac just open the terminal in place of the command prompt and go through the following commands.

pip install django
django-admin startproject pkapp (projectname)
cd pkapp
python manage.py runserver
Create app in django

python manage.py startapp home
urls.py (from python's project folder)

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('home.urls')), (if get any path then send to home app)
]
urls.py (from home (python's app folder ))

from django.contrib import admin
from django.urls import path, include
from home import views

urlpatterns = [
    path('', views.index, name='home'), (views is a file of home app and index is the 
                                         function from views.py file)
    path('about', views.about, name='about'),
    path('services', views.services, name='services'),
    path('blog', views.blog, name='blog'),
    path('contact', views.contact, name='contact'),
]
views.py (from home folder)

from django.shortcuts import render, HttpResponse
# Create your views here.

def index(request):
    return HttpResponse('this is home page')

def about(request):
    return HttpResponse('this is about page')

def services(request);
    return HttpResponse('this is services page')

def blog(request):
    return HttpResponse('this is blog page')

def contact(request):
    return HttpResponse('this is contact page')
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver ( run the server )

 

 

 

 

 

Leave a Reply