Introduction to
Jyoti Sachdeva
Software Consultant
Knoldus
Agenda
● What is Django?
● Why Django?
● Install Django
● Create Project in Django
● Project Structure
● Run application
● Django Admin / Manage.py
● Create Application in Django
● Templates
● Template Inheritance
Agenda Contd.
● Models
● Django Shell
● Register Model
● Django Architecture
What is Django?
● High level Web Framework
● Free and open source
● Batteries Included
● Build in Python
Why Django?
● Fast
● Tons of Packages
● Secure
● Scalable
● Versatile
● Loosely Coupled
● Admin Interface
● ORM
Install Django
● pip install django
● pip install django === version number
● django-admin --version
Create Project in Django
● django-admin startproject django_proj
● django-admin help
Django’s command-line utility for administrative tasks.
Project Structure
Run Application
python manage.py runserver
Django Admin/Manage.py
● python manage.py migrate
● python manage.py createsuperuser
Create Application in Django
● python manage.py startapp blog
Register app to plug them for templates
Application and Routes
Templates
Template Inheritance
● Create common template using block
● Extend the block in other html files
Models
● python manage.py sqlmigrate blog 0001
● Python manage.py showmigrations
Models
Django Shell
● python manage.py shell
Django Shell
Register Model
● admin.site.register(Post)
Django Architecture
Django follows MVT pattern. MVT is a software design pattern. It is a collection of
three important components Model View and Template.
Model: The Model helps to handle database. It is the backend where your
database is defined.
Template: The Template handles User Interface part completely
View: The View is used to execute the business logic and interact with a model to
carry data and renders a template.A user sends the request via the browser.
Django works as a controller and checks to the available resource in URL. If URL
maps, a view is called.The view interacts with model and template, retrieves data
from the database via the model, formats it, render a template as a response.
Django Architecture
Django Architecture
References
● https://docs.djangoproject.com
● Youtube - Corey Schafer
Thank You !

Introduction to Django