SlideShare a Scribd company logo
Web development with Django 
© Shrinath Shenoy
What is Django 
Django is a MVC like framework ( Django 
community call it as MTV - Model, View, Template 
) written in pure python 
Django can be used with databases like 
Postgresql, MySQL, sqlite, MongoDB, Oracle etc..
Who are using Django 
Mozilla ( support.mozilla.com, addons.mozilla.org ) 
Google ( developers.google.com, app engine cloud sql 
) 
Disqus 
Pinterest 
Instagram 
bitbucket 
newyorktimes.com (represent) 
washingtonpost.com 
guardian.co.uk 
developer.vodafone.com 
nationalgeographic.com
Creating a django project 
Start a new project from 
django-admin.py startproject projectname 
It will create project folders in the following 
structure 
projectname/ 
manage.py 
projectname/ 
__init__.py 
settings.py 
urls.py 
wsgi.py
Django Project Structure 
python manage.py startapp appname 
projectname/ 
manage.py 
appname/ 
__init__.py 
models.py 
tests.py 
views.py 
projectname/ 
__init__.py 
settings.py 
urls.py 
wsgi.py
settings.py 
This contains all the settings related to the 
project. Like DB username-password-connection- 
port, middlewares, logs, dev 
settings, media path etc. 
The settings.py file is used as default 
configuration file while running the server. If you 
have some other settings file then you can tell 
the server to use that by setting the environment 
vairable DJANGO_SETTINGS_MODULE
urls.py 
• URL patterns are definied in this file. 
• URL patterns will be made up of regular 
expressions of the url patterns. 
• The function/view that needs to be called are 
mapped here. 
• Best Practice : Maintain a urls.py inside each app 
to avoid the global urls.py mess
A typical urls mapping looks like this 
from django.conf.urls import patterns, url 
urlpatterns += patterns('', 
urlpatterns = ( 
url(r'^$', views.index, name='index'), 
)
views.py 
The request lands here after the url requested is mapped to 
a view through middlewares. 
There are two types of view. That a user can opt for 
depending on the requirement. 
1. Function Based View 
2. Classbased view 
Function based views are normal python functions that take 
request and curresponding custom parameter if any. 
Class Based views are the special views that is required to 
be inheriting the django's predefined view/any other class 
that satisfy the condition to map the url to a class based 
view ( Better to inherit the view class given by django :) )
• There are lot of built in views that can be used 
accordingly. ( e.g. listview - if you want just to list 
the objects of a model that satisfy a queryset ) 
• url definition will take function based view ( FBV 
) as second argument. This will make the view 
function gets called for that url. Where as Class 
based view's as_view() function should be feed 
to url definition. The reason is given below. 
• Class Based Views ( CBV ) has the intelligence 
to find the method used in request ( get, post or 
any other ) and dispatche the data come along 
with the request to curresonding method.
• Each view must return a response or raise the relevant 
exeption if any. 
• response can contain the django template, file, JSON 
objects or even just HTTP Status codes.
A typical Django FBV would look like this 
from django.http import HttpResponse 
import datetime 
def current_datetime(request): 
now = datetime.datetime.now() 
html = "<html><body>Its now %s</body></html>" 
% now 
return HttpResponse(html)
A typical Django CBV would look like this 
import datetime 
from django.http import HttpResponse 
from django.views.generic import View 
class ShowDateView(View): 
def get(request): 
now = datetime.datetime.now() 
html = "<html><body>Its now %s</body></html>" 
% now 
return HttpResponse(html)
models.py 
Models.py file is the place to put the details about 
the DB tables that we need in our app. 
Models can be imagined as DB Table - definition 
written in python :) 
Models are the normal python classes that inherit 
from the Django "Model" class found in 
django.db.models module. 
The class attributes/member-variables defines the 
columns and data type of their curresponding db 
tables.
• models will have thier own "manager" objects 
that will be used to query the table. 
• Django ORM provides the "query functions" in 
each models through thier "manager" objects. 
• Each model object will have their save() method 
to save the model "instance" into database. 
• models have built in validators which will validate 
the model object values against their datatype 
and constraints.
A typical django model would look like 
from django.db import models 
class UserProfile(models.Model): 
first_name = models.CharField(max_lenght=10) 
last_name = models.CharField(max_lenght=10) 
phone_number = models.IntegerField(null=True)
Availble Built in Fields in Django models 
AutoField 
BigIntegerField 
BooleanField 
CharField 
CommaSeparatedIntegerField 
DateField 
DateTimeField 
DecimalField 
EmailField 
FileField
forms.py 
Django forms which is used to process web form 
data are similar to django model classes. But 
django froms deal with the incoming data from 
client rather than database. 
Similar to Django models django forms are python 
classes inheriting from Django's django.form 
module
A django form declaration would look like 
from django import forms 
class LoginForm(forms.Form): 
username = forms.CharField(max_length=12) 
password = forms.CharField(max_lenght=12, att)
Django Forms built in Fields 
BooleanFieldCharField ChoiceField 
DateField DateTimeField 
EmailField FileField 
FloatField ImageField 
IPAddressField GenericIPAddressField 
TypedMultipleChoiceField NullBooleanField 
SlugField TimeField 
TypedChoiceField DecimalField 
FilePathField IntegerField 
MultipleChoiceField RegexField 
URLField
templates 
Django templates are the files (Usually HTML ) which allow 
us to insert the django variables inside them and write very 
minimalistic processing like iterating over a loop, trimming 
the string, adding integers inside them etc. 
Django templates are designed to make it reusable. Like a 
class, you can inherite a template and override the portions 
of it. 
Django template engine comes with built in tags and filters 
which can be used to process the data before rendering. 
Even django allows you to create your own custom tags 
and filters. So that you can define your custom behaviors in 
the template.
Django templates should be written in such a way that only 
rendering process will be held in that. No complex logical 
algorithm shoul be handled inside the templates. 
Django template are designed such that it uses the less of 
programming language, and more of the designing part so 
that any web designer knowing only creating 
HTML/CSS/Javascript can develop it without having the 
exposure to the python.
Django Principles 
DRY ( Don't Repeat Yourself ) 
Loose Coupling 
Less Code 
Explicit is better than implicit 
Infinite flexibility in url 
Separate logic from presentation 
Be decoupled from HTML
Benifits/Pros of using Django 
Easy to understand and easily maintainable 
code 
Write less do more with python-django 
combination. 
Lot of opensource plugins available that can be 
used along with django. You just need to 
import and use it in your code.
Django has lot of built-ins which are more 
commonly needed functionalities in a web app 
along with additional goodies. 
• User authentication and password management 
• Pagination 
• Form-Model validation 
• Caching 
• Admin Panel 
• Session management 
• Protection via clickjacking and cross site
• Localization 
• Email Integration 
• RSS Feeds Integration 
• Sitemap Integration 
• CSV/PDF save/export integration 
• Geographical Query Support
Thank You..!! 
: 
)

More Related Content

What's hot

Flask – Python
Flask – PythonFlask – Python
Flask – Python
Max Claus Nunes
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
Knoldus Inc.
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
Haiqi Chen
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Edureka!
 
Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...
Edureka!
 
Django Interview Questions and Answers
Django Interview Questions and AnswersDjango Interview Questions and Answers
Django Interview Questions and Answers
Python Devloper
 
Intro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoIntro to Web Development Using Python and Django
Intro to Web Development Using Python and Django
Chariza Pladin
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
Introduction to Django Rest Framework
Introduction to Django Rest FrameworkIntroduction to Django Rest Framework
Introduction to Django Rest Framework
bangaloredjangousergroup
 
Django Seminar
Django SeminarDjango Seminar
Django Seminar
Yokesh Rana
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
Michael Pirnat
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
Simplilearn
 
django
djangodjango
DJango
DJangoDJango
DJango
Sunil OS
 
What Are Python Modules? Edureka
What Are Python Modules? EdurekaWhat Are Python Modules? Edureka
What Are Python Modules? Edureka
Edureka!
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Python/Django Training
Python/Django TrainingPython/Django Training
Python/Django Training
University of Technology
 
Database programming
Database programmingDatabase programming

What's hot (20)

Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
 
Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...
 
Django Interview Questions and Answers
Django Interview Questions and AnswersDjango Interview Questions and Answers
Django Interview Questions and Answers
 
Intro to Web Development Using Python and Django
Intro to Web Development Using Python and DjangoIntro to Web Development Using Python and Django
Intro to Web Development Using Python and Django
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Introduction to Django Rest Framework
Introduction to Django Rest FrameworkIntroduction to Django Rest Framework
Introduction to Django Rest Framework
 
Django Seminar
Django SeminarDjango Seminar
Django Seminar
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
 
django
djangodjango
django
 
DJango
DJangoDJango
DJango
 
What Are Python Modules? Edureka
What Are Python Modules? EdurekaWhat Are Python Modules? Edureka
What Are Python Modules? Edureka
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Python/Django Training
Python/Django TrainingPython/Django Training
Python/Django Training
 
Database programming
Database programmingDatabase programming
Database programming
 

Similar to Web development with django - Basics Presentation

Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)
Nishant Soni
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
Joaquim Rocha
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
salemsg
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030Kevin Wu
 
A gentle intro to the Django Framework
A gentle intro to the Django FrameworkA gentle intro to the Django Framework
A gentle intro to the Django FrameworkRicardo Soares
 
learnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptxlearnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptx
bestboybulshaawi
 
Django
DjangoDjango
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
railsbootcamp
 
Django Frequently Asked Interview Questions
Django Frequently Asked Interview QuestionsDjango Frequently Asked Interview Questions
Django Frequently Asked Interview Questions
AshishMishra308598
 
* DJANGO - The Python Framework - Low Kian Seong, Developer
    * DJANGO - The Python Framework - Low Kian Seong, Developer    * DJANGO - The Python Framework - Low Kian Seong, Developer
* DJANGO - The Python Framework - Low Kian Seong, DeveloperLinuxmalaysia Malaysia
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
Tikal Knowledge
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Tony Frame
 
templates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtratemplates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtra
baabtra.com - No. 1 supplier of quality freshers
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
MoniaJ
 
Tango with django
Tango with djangoTango with django
Tango with django
Rajan Kumar Upadhyay
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
Ksd Che
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheet
Lam Hoang
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
colinkingswood
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
Wade Austin
 

Similar to Web development with django - Basics Presentation (20)

Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)Rapid web application development using django - Part (1)
Rapid web application development using django - Part (1)
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
 
A gentle intro to the Django Framework
A gentle intro to the Django FrameworkA gentle intro to the Django Framework
A gentle intro to the Django Framework
 
learnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptxlearnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptx
 
Django
DjangoDjango
Django
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
Django Frequently Asked Interview Questions
Django Frequently Asked Interview QuestionsDjango Frequently Asked Interview Questions
Django Frequently Asked Interview Questions
 
* DJANGO - The Python Framework - Low Kian Seong, Developer
    * DJANGO - The Python Framework - Low Kian Seong, Developer    * DJANGO - The Python Framework - Low Kian Seong, Developer
* DJANGO - The Python Framework - Low Kian Seong, Developer
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
 
templates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtratemplates in Django material : Training available at Baabtra
templates in Django material : Training available at Baabtra
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
 
Tango with django
Tango with djangoTango with django
Tango with django
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheet
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 

Recently uploaded

TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 

Recently uploaded (20)

TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 

Web development with django - Basics Presentation

  • 1. Web development with Django © Shrinath Shenoy
  • 2. What is Django Django is a MVC like framework ( Django community call it as MTV - Model, View, Template ) written in pure python Django can be used with databases like Postgresql, MySQL, sqlite, MongoDB, Oracle etc..
  • 3. Who are using Django Mozilla ( support.mozilla.com, addons.mozilla.org ) Google ( developers.google.com, app engine cloud sql ) Disqus Pinterest Instagram bitbucket newyorktimes.com (represent) washingtonpost.com guardian.co.uk developer.vodafone.com nationalgeographic.com
  • 4. Creating a django project Start a new project from django-admin.py startproject projectname It will create project folders in the following structure projectname/ manage.py projectname/ __init__.py settings.py urls.py wsgi.py
  • 5. Django Project Structure python manage.py startapp appname projectname/ manage.py appname/ __init__.py models.py tests.py views.py projectname/ __init__.py settings.py urls.py wsgi.py
  • 6. settings.py This contains all the settings related to the project. Like DB username-password-connection- port, middlewares, logs, dev settings, media path etc. The settings.py file is used as default configuration file while running the server. If you have some other settings file then you can tell the server to use that by setting the environment vairable DJANGO_SETTINGS_MODULE
  • 7. urls.py • URL patterns are definied in this file. • URL patterns will be made up of regular expressions of the url patterns. • The function/view that needs to be called are mapped here. • Best Practice : Maintain a urls.py inside each app to avoid the global urls.py mess
  • 8. A typical urls mapping looks like this from django.conf.urls import patterns, url urlpatterns += patterns('', urlpatterns = ( url(r'^$', views.index, name='index'), )
  • 9. views.py The request lands here after the url requested is mapped to a view through middlewares. There are two types of view. That a user can opt for depending on the requirement. 1. Function Based View 2. Classbased view Function based views are normal python functions that take request and curresponding custom parameter if any. Class Based views are the special views that is required to be inheriting the django's predefined view/any other class that satisfy the condition to map the url to a class based view ( Better to inherit the view class given by django :) )
  • 10. • There are lot of built in views that can be used accordingly. ( e.g. listview - if you want just to list the objects of a model that satisfy a queryset ) • url definition will take function based view ( FBV ) as second argument. This will make the view function gets called for that url. Where as Class based view's as_view() function should be feed to url definition. The reason is given below. • Class Based Views ( CBV ) has the intelligence to find the method used in request ( get, post or any other ) and dispatche the data come along with the request to curresonding method.
  • 11. • Each view must return a response or raise the relevant exeption if any. • response can contain the django template, file, JSON objects or even just HTTP Status codes.
  • 12. A typical Django FBV would look like this from django.http import HttpResponse import datetime def current_datetime(request): now = datetime.datetime.now() html = "<html><body>Its now %s</body></html>" % now return HttpResponse(html)
  • 13. A typical Django CBV would look like this import datetime from django.http import HttpResponse from django.views.generic import View class ShowDateView(View): def get(request): now = datetime.datetime.now() html = "<html><body>Its now %s</body></html>" % now return HttpResponse(html)
  • 14. models.py Models.py file is the place to put the details about the DB tables that we need in our app. Models can be imagined as DB Table - definition written in python :) Models are the normal python classes that inherit from the Django "Model" class found in django.db.models module. The class attributes/member-variables defines the columns and data type of their curresponding db tables.
  • 15. • models will have thier own "manager" objects that will be used to query the table. • Django ORM provides the "query functions" in each models through thier "manager" objects. • Each model object will have their save() method to save the model "instance" into database. • models have built in validators which will validate the model object values against their datatype and constraints.
  • 16. A typical django model would look like from django.db import models class UserProfile(models.Model): first_name = models.CharField(max_lenght=10) last_name = models.CharField(max_lenght=10) phone_number = models.IntegerField(null=True)
  • 17. Availble Built in Fields in Django models AutoField BigIntegerField BooleanField CharField CommaSeparatedIntegerField DateField DateTimeField DecimalField EmailField FileField
  • 18. forms.py Django forms which is used to process web form data are similar to django model classes. But django froms deal with the incoming data from client rather than database. Similar to Django models django forms are python classes inheriting from Django's django.form module
  • 19. A django form declaration would look like from django import forms class LoginForm(forms.Form): username = forms.CharField(max_length=12) password = forms.CharField(max_lenght=12, att)
  • 20. Django Forms built in Fields BooleanFieldCharField ChoiceField DateField DateTimeField EmailField FileField FloatField ImageField IPAddressField GenericIPAddressField TypedMultipleChoiceField NullBooleanField SlugField TimeField TypedChoiceField DecimalField FilePathField IntegerField MultipleChoiceField RegexField URLField
  • 21. templates Django templates are the files (Usually HTML ) which allow us to insert the django variables inside them and write very minimalistic processing like iterating over a loop, trimming the string, adding integers inside them etc. Django templates are designed to make it reusable. Like a class, you can inherite a template and override the portions of it. Django template engine comes with built in tags and filters which can be used to process the data before rendering. Even django allows you to create your own custom tags and filters. So that you can define your custom behaviors in the template.
  • 22. Django templates should be written in such a way that only rendering process will be held in that. No complex logical algorithm shoul be handled inside the templates. Django template are designed such that it uses the less of programming language, and more of the designing part so that any web designer knowing only creating HTML/CSS/Javascript can develop it without having the exposure to the python.
  • 23. Django Principles DRY ( Don't Repeat Yourself ) Loose Coupling Less Code Explicit is better than implicit Infinite flexibility in url Separate logic from presentation Be decoupled from HTML
  • 24. Benifits/Pros of using Django Easy to understand and easily maintainable code Write less do more with python-django combination. Lot of opensource plugins available that can be used along with django. You just need to import and use it in your code.
  • 25. Django has lot of built-ins which are more commonly needed functionalities in a web app along with additional goodies. • User authentication and password management • Pagination • Form-Model validation • Caching • Admin Panel • Session management • Protection via clickjacking and cross site
  • 26. • Localization • Email Integration • RSS Feeds Integration • Sitemap Integration • CSV/PDF save/export integration • Geographical Query Support