N. Achyut Python,Uncategorized Installing Django Project in 5 minutes

Installing Django Project in 5 minutes

All codes below to be typed on commandprompt or windows powershell

Step 1: pip install django (install django )
Step 2:cd desktop (enter desktop directory)
Step 3:django-admin startproject django8am (to create new project..here django8am is the project foldername )
Step 4:cd django8am (enter django project folder)
Step 5: py manage.py runserver (to run django server)
127.0.0.1:8000


Then ,to create specified folder for certain task and implementing the website follow the following task once above task is completed .

Step 1: change directory to the django8am folder
C:Usersuserdesktopcd django8am
=C:Usersuserdesktopdjango8am>
Step 2:open new app(folder) inside django8am using the command:
py manage.py startapp news (here news is the app name)
Step 3:create a python file named “urls.py ” inside the news folder
Step 4: 1)Open apps.py of the news folder.
2)copy the classname for the news.

class NewsConfig(AppConfig):
    	          name = 'news'

here Newsconfig is the class name for the news.
3)open settings.py of django8am.
4)register the news inside the INSTALLED_APPS as

INSTALLED_APPS=[
	           'news.apps.Newsconfig',
	            ......		
	        ]

5)Open urls.py of django8am and include the following code:

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

	      urlpatterns = [
    	       path('', include('news.urls')),
    	       path('admin/', admin.site.urls),
	        ]

6)Open urls.py of news and include the following :

from django.urls import path
from . import views

	     urlpatterns = [
	      path('', views.index),
 	      path('about', views.about),
	       ]

7)Open directory named templates inside news and add the directory name templates
in the TEMPLATES >DIRS of settings.py of django8am.
in templates directory of news , we can add html files.
8)Open views.py of news and add the below codes for viewing the project created.

from django.shortcuts import render
from django.http import HttpResponse

Create your views here.

def index(request):
    return render(request,'index.html')


def about(request):
    return render(request,'about.html')

Related Post