Django Framework
Django is a high-level Python web framework that encourages rapid development and clean,
pragmatic design.
Official Website - [Link]
Django follows the Model-View-Template (MVT) pattern.
The Model-View-Template (MVT) is slightly different from MVC. In fact the main difference
between the two patterns is that Django itself takes care of the Controller part.
Django comes with a lightweight web server for developing and testing applications.
The Project Structure
[Link] − This file is kind of your project local django-admin for interacting with your project
via command line
__init__.py − Treat this folder as package.
[Link] − As the name indicates, your project settings.
[Link] − All links of your project and the function to call..
[Link] − If you need to deploy your project over WSGI.
Application Structure
__init__.py − Treat this folder as package.
[Link] − This file helps you make the app modifiable in the admin interface.
[Link] − the application models are stored.
[Link] − This is where your unit tests are.
[Link] − application views.
KL University – Department of CSE – Y21 – 21TS2101AA - Python Full Stack Development 1
Django Layout
Initial Setup for for an Django Project
Step 1: Installing Virtual env
pip install virtualenvwrapper-win
Step 2: Create the virtual environment
mkvirtualenv test1
Step 2.1: Activate the virtual environment
mypthon\Scripts\activate
Step 2.2: Deactivate the virtual environment
Deactivate
Step 3: Install Django package
pip install Django
Step 3.1: Check Django package version
django-admin --version
KL University – Department of CSE – Y21 – 21TS2101AA - Python Full Stack Development 2
Step 4 : Create Project
django-admin startproject example1
Step 4.1 : Get into the Project
cd example1
Step 5 : Command to run the Django project
python [Link] runserver
Step 6 : Url to start the Django project
[Link]
Hello World Program Using Django Framework
Step 7 : Command to create new app
python [Link] startapp print_hello
Step 8 : Create [Link] in print_hello
from [Link] import path
from . import views
urlpatterns = [
path('',[Link], name = 'home')
]
Step 9 : Modify [Link] in print_hello
from [Link] import render
from [Link] import HttpResponse
# Create your views here.
def home(request):
return HttpResponse("Hello World Example of PFSD Program")
Step 10 : Modify [Link] in Project – [Link]
path('',include('print_hello.urls'))
Step 11 : Add 1 line in Project – [Link]
INSTALLED_APPS = [
'print_hello'
]
Step 12 : Run the code
Python [Link] runserver
KL University – Department of CSE – Y21 – 21TS2101AA - Python Full Stack Development 3