0% found this document useful (0 votes)
129 views3 pages

Y22 - PFSD - Django First Class

Django is a Python web framework that follows the MVT (Model-View-Template) pattern. It encourages rapid development and clean, pragmatic design. A Django project contains a manage.py file, project settings, URLs, and may contain one or more applications. Each application contains models, views, tests, and other files that make up its functionality. Django provides a lightweight development server and tools to interact with projects via the command line.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views3 pages

Y22 - PFSD - Django First Class

Django is a Python web framework that follows the MVT (Model-View-Template) pattern. It encourages rapid development and clean, pragmatic design. A Django project contains a manage.py file, project settings, URLs, and may contain one or more applications. Each application contains models, views, tests, and other files that make up its functionality. Django provides a lightweight development server and tools to interact with projects via the command line.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Django Framework

 Django is a high-level Python web framework that encourages rapid development and clean,
pragmatic design.
 Official Website - https://www.djangoproject.com/
 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


 manage.py − 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.
 settings.py − As the name indicates, your project settings.
 urls.py − All links of your project and the function to call..
 wsgi.py − If you need to deploy your project over WSGI.

Application Structure
 __init__.py − Treat this folder as package.
 admin.py − This file helps you make the app modifiable in the admin interface.
 models.py − the application models are stored.
 tests.py − This is where your unit tests are.
 views.py − 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 manage.py runserver

Step 6 : Url to start the Django project


http://127.0.0.1:8000/

Hello World Program Using Django Framework


Step 7 : Command to create new app
python manage.py startapp print_hello

Step 8 : Create urls.py in print_hello

from django.urls import path


from . import views

urlpatterns = [
path('',views.home, name = 'home')
]

Step 9 : Modify views.py in print_hello

from django.shortcuts import render


from django.http import HttpResponse

# Create your views here.


def home(request):
return HttpResponse("Hello World Example of PFSD Program")

Step 10 : Modify urls.py in Project – urls.py


path('',include('print_hello.urls'))

Step 11 : Add 1 line in Project – settings.py


INSTALLED_APPS = [
'print_hello'
]

Step 12 : Run the code


Python manage.py runserver
KL University – Department of CSE – Y21 – 21TS2101AA - Python Full Stack Development 3

You might also like