SlideShare uma empresa Scribd logo
1 de 12
Python Web Framework
Balakumar Parameshwaran
24-10-2013

http://www.balakumarp.com
Agenda
 Introduction
 Features
 Installation
 Django Architecture
 Project structure
 Settings

 Project / Site creation
 URL Dispatcher
 Who uses it?

 Questions

2
Introduction
Django is a free and open source web application framework, written in
Python, which follows the Model–View–Controller architectural pattern.
It is maintained by the Django Software Foundation (DSF), an
independent organization.
 Encourages rapid development and clean, pragmatic design.

 Named after famous Guitarist Django Reinhardt
 Developed by Adrian Holovaty & Jacob Kaplan-moss
 Created in 2003, open sourced in 2005
 1.0 Version released in Sep 3 2008, now 1.5.4

3
Features


Object Relational Mapper - ORM



MVC (MVT) Architecture



Focuses on automating as much as possible and adhering to the DRY principle



Template System



Out of the box customizable Admin Interface, makes CRUD easy



Built-in light weight Web Server



Elegant URL design



Custom Middleware



Authentication / Authorization



Internationalization support



Cache framework, with multiple cache mechanisms



Fast Development



Free, and Great Documentation
4
Installation
Prerequisites



Python
PIP for installing Python packages (http://www.pip-installer.org/en/latest/installing.html)

 pip install Django==1.5.4
o

OR https://www.djangoproject.com/download/ - python setup.py install

 pip install mysql-python
o

MySQL on windows https://pypi.python.org/pypi/MySQL-python/1.2.4

 Add Python and Django to env path
o

PYTHONPATH D:Python27

o

Path D:Python27; D:Python27Libsite-packages; D:Python27Libsite-packagesdjangobin;

 Testing installation
o

shell> import django; django.VERSION;

5
Django Architecture
Models
Views
Templates
Controller

Describes your data
Controls what users sees
How user sees it
URL dispatcher

6
Project Directory Structure
demosite/ ---------------------------------- Just a container for your project. Its name doesn’t

matter to Django; you can rename

it to anything you like.

manage.py ------------------------- A command-line utility that lets you interact with this Django project in various ways.
Type python manage.py help. You should never have to edit this file.

demosite/ ------------------------- Actual Python package for your project. Use this name to import anything inside it
(e.g. import demosite.settings)

__init__.py ----------------- A file required for Python to treat the demosite directory as a package.
settings.py ----------------- Settings/configuration for this Django project
urls.py ---------------------- Root URL config, the URLs for this Django project, provides mapping to views
wsgi.py ---------------------- An entry-point for WSGI-compatible webservers to serve your project
templates/ ----------------- HTML files , renders based on views. You can change to any dir, configurable in settings.py
static/ ----------------------- CSS, JS, images.. etc, configurable in settings.py
demoapp/ ----------------__init__.py -------urls.py -----------views.py ---------- Responsible for processing a user’s request and for returning the response
models.py --------- A model is the single, definitive source of information about your data.
Generally, each model maps to a single database table.

admin.py ---------- It reads metadata in your model to provide a powerful and production-ready interface
forms.py ----------- To create and manipulate form data
7
Settings


Project settings.py overrides from <python>/Lib/site-packgaes/django/conf/global_settings.py



Set DJANGO_SETTINGS_MODULE for your Project, tells django which settings to be used. (demoproject.settings)


export/set DJANGO_SETTINGS_MODULE=demoproject.settings



For server mod_wsgi: os.environ['DJANGO_SETTINGS_MODULE'] = 'demoproject.settings'



DEBUG

True or False



DATABASES ENGINE

postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.. etc



ROOT_URLCONF



MEDIA_ROOT

directory that will hold user-uploaded files



MEDIA_URL

To serve media files



STATIC_ROOT

To any server static files css, js.. and admin UI files (can add more dirs to STATICFILES_DIRS)



STATIC_URL

To serve static files



TEMPLATE_DIRS

Template directories

Using settings in Python code
from django.conf import settings
if settings.DEBUG:
# Do something
8
Project / Site Creation
 Creating new Project


django-admin.py startproject demoproject

A project is a collection of applications

 Creating new Application


python manage.py startapp demosite

An application tries to provide a single, relatively self-contained set of related functions

 Using the built-in web server


python manage.py runserver



python manage.py runserver 80

Runs by default at port 8000
It checks for any error and validate the models. Throws errors/warnings for any misconfigurations and invalid
entries.

9
URL Dispatcher / Patterns


Root URL should be configured in settings.py
o



ROOT_URLCONF = 'app.urls'

Syntax
patterns(prefix,
(regular expression, Python callback function [, optional dictionary [, optional name]])
)
Example:
urlpatterns = patterns(' ',
(r'^articles-year/$', 'mysite.news.views.articles_year'),
)
Note:
o No need to add a leading slash (/articles-year)
o The 'r' in front of each regular expression string is optional but recommended. It tells Python that a
string is "raw" -- that nothing in the string should be escaped.
In python, the ‘’ backslash character in control chars must be escaped for regular expression use.
Basically we have to add one more slash i.e t, b. To work around backslash plague, you can raw string,
by prefixing the string with the letter r.
10


Can include other URLconf modules
urlpatterns = patterns(' ',
url(r'^support/', include('demoproject.support.urls')),
)



Using Prefix
urlpatterns = patterns(' ',
(r'^articles/(d{4})/$', 'mysite.news.views.articles_year'),
(r'^articles/(d{4})/(d{2})/$', 'mysite.news.views.articles_month'),

)
Here mysite.news.views is common, so can be rewritten as follows
urlpatterns = patterns('mysite.news.views',
(r'^articles/(d{4})/$', 'articles_year'),
(r'^articles/(d{4})/(d{2})/$', 'articles_month'),

)



Passing extra arguments and Dictionary mapping
patterns(' ',
(r'^articles/(?P<year>d{4})/$', 'articles_year'), {'foo': 'bar'}),
)
We can get the values in views.py as year='2005', foo='bar'

11
Who uses Django?
 BitBucket

 DISQUS (serving 400 million people)
 Pinterest
 Instagram
 dPaste
 Mozilla (support.mozill, addons.mozilla)
 NASA
 PBS (Public Broadcasting Service)

 The Washington Post, NY Times, LA Times, The Guardian
 National Geographic, Discovery Channel

12

Mais conteúdo relacionado

Mais procurados

Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoKnoldus Inc.
 
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!
 
Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics PresentationShrinath Shenoy
 
Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Tom Brander
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersRosario Renga
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
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 Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsSolution4Future
 

Mais procurados (20)

Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
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...
 
Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics Presentation
 
Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Django, What is it, Why is it cool?
Django, What is it, Why is it cool?
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Django
DjangoDjango
Django
 
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
DjangoDjango
Django
 
django
djangodjango
django
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
DJango
DJangoDJango
DJango
 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Django Girls Tutorial
Django Girls TutorialDjango Girls Tutorial
Django Girls Tutorial
 
Python/Django Training
Python/Django TrainingPython/Django Training
Python/Django Training
 
Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in python
 
Django
DjangoDjango
Django
 

Semelhante a Django - Python MVC Framework

Django framework
Django framework Django framework
Django framework TIB Academy
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem vAkash Rajguru
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in DjangoLakshman Prasad
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگوrailsbootcamp
 
How to lock a Python in a cage? Managing Python environment inside an R project
How to lock a Python in a cage?  Managing Python environment inside an R projectHow to lock a Python in a cage?  Managing Python environment inside an R project
How to lock a Python in a cage? Managing Python environment inside an R projectWLOG Solutions
 
Developing Drizzle Replication Plugins
Developing Drizzle Replication PluginsDeveloping Drizzle Replication Plugins
Developing Drizzle Replication PluginsPadraig O'Sullivan
 
Continuous Deployment @ AWS Re:Invent
Continuous Deployment @ AWS Re:InventContinuous Deployment @ AWS Re:Invent
Continuous Deployment @ AWS Re:InventJohn Schneider
 
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...Amazon Web Services
 
OpenERP Technical Memento V0.7.3
OpenERP Technical Memento V0.7.3OpenERP Technical Memento V0.7.3
OpenERP Technical Memento V0.7.3Borni DHIFI
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docxfantabulous2024
 
Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesLeonardo Fernandes
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingAlessandro Molina
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaMark Leith
 
Let's build Developer Portal with Backstage
Let's build Developer Portal with BackstageLet's build Developer Portal with Backstage
Let's build Developer Portal with BackstageOpsta
 
Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Quang Ngoc
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Gunith Devasurendra
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 

Semelhante a Django - Python MVC Framework (20)

Django framework
Django framework Django framework
Django framework
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem v
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in Django
 
Django
DjangoDjango
Django
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
How to lock a Python in a cage? Managing Python environment inside an R project
How to lock a Python in a cage?  Managing Python environment inside an R projectHow to lock a Python in a cage?  Managing Python environment inside an R project
How to lock a Python in a cage? Managing Python environment inside an R project
 
Developing Drizzle Replication Plugins
Developing Drizzle Replication PluginsDeveloping Drizzle Replication Plugins
Developing Drizzle Replication Plugins
 
Continuous Deployment @ AWS Re:Invent
Continuous Deployment @ AWS Re:InventContinuous Deployment @ AWS Re:Invent
Continuous Deployment @ AWS Re:Invent
 
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
 
OpenERP Technical Memento V0.7.3
OpenERP Technical Memento V0.7.3OpenERP Technical Memento V0.7.3
OpenERP Technical Memento V0.7.3
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
 
Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico Ces
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
Rest api with Python
Rest api with PythonRest api with Python
Rest api with Python
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
 
Let's build Developer Portal with Backstage
Let's build Developer Portal with BackstageLet's build Developer Portal with Backstage
Let's build Developer Portal with Backstage
 
Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
Heroku pycon
Heroku pyconHeroku pycon
Heroku pycon
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Último (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Django - Python MVC Framework

  • 1. Python Web Framework Balakumar Parameshwaran 24-10-2013 http://www.balakumarp.com
  • 2. Agenda  Introduction  Features  Installation  Django Architecture  Project structure  Settings  Project / Site creation  URL Dispatcher  Who uses it?  Questions 2
  • 3. Introduction Django is a free and open source web application framework, written in Python, which follows the Model–View–Controller architectural pattern. It is maintained by the Django Software Foundation (DSF), an independent organization.  Encourages rapid development and clean, pragmatic design.  Named after famous Guitarist Django Reinhardt  Developed by Adrian Holovaty & Jacob Kaplan-moss  Created in 2003, open sourced in 2005  1.0 Version released in Sep 3 2008, now 1.5.4 3
  • 4. Features  Object Relational Mapper - ORM  MVC (MVT) Architecture  Focuses on automating as much as possible and adhering to the DRY principle  Template System  Out of the box customizable Admin Interface, makes CRUD easy  Built-in light weight Web Server  Elegant URL design  Custom Middleware  Authentication / Authorization  Internationalization support  Cache framework, with multiple cache mechanisms  Fast Development  Free, and Great Documentation 4
  • 5. Installation Prerequisites   Python PIP for installing Python packages (http://www.pip-installer.org/en/latest/installing.html)  pip install Django==1.5.4 o OR https://www.djangoproject.com/download/ - python setup.py install  pip install mysql-python o MySQL on windows https://pypi.python.org/pypi/MySQL-python/1.2.4  Add Python and Django to env path o PYTHONPATH D:Python27 o Path D:Python27; D:Python27Libsite-packages; D:Python27Libsite-packagesdjangobin;  Testing installation o shell> import django; django.VERSION; 5
  • 6. Django Architecture Models Views Templates Controller Describes your data Controls what users sees How user sees it URL dispatcher 6
  • 7. Project Directory Structure demosite/ ---------------------------------- Just a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like. manage.py ------------------------- A command-line utility that lets you interact with this Django project in various ways. Type python manage.py help. You should never have to edit this file. demosite/ ------------------------- Actual Python package for your project. Use this name to import anything inside it (e.g. import demosite.settings) __init__.py ----------------- A file required for Python to treat the demosite directory as a package. settings.py ----------------- Settings/configuration for this Django project urls.py ---------------------- Root URL config, the URLs for this Django project, provides mapping to views wsgi.py ---------------------- An entry-point for WSGI-compatible webservers to serve your project templates/ ----------------- HTML files , renders based on views. You can change to any dir, configurable in settings.py static/ ----------------------- CSS, JS, images.. etc, configurable in settings.py demoapp/ ----------------__init__.py -------urls.py -----------views.py ---------- Responsible for processing a user’s request and for returning the response models.py --------- A model is the single, definitive source of information about your data. Generally, each model maps to a single database table. admin.py ---------- It reads metadata in your model to provide a powerful and production-ready interface forms.py ----------- To create and manipulate form data 7
  • 8. Settings  Project settings.py overrides from <python>/Lib/site-packgaes/django/conf/global_settings.py  Set DJANGO_SETTINGS_MODULE for your Project, tells django which settings to be used. (demoproject.settings)  export/set DJANGO_SETTINGS_MODULE=demoproject.settings  For server mod_wsgi: os.environ['DJANGO_SETTINGS_MODULE'] = 'demoproject.settings'  DEBUG True or False  DATABASES ENGINE postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.. etc  ROOT_URLCONF  MEDIA_ROOT directory that will hold user-uploaded files  MEDIA_URL To serve media files  STATIC_ROOT To any server static files css, js.. and admin UI files (can add more dirs to STATICFILES_DIRS)  STATIC_URL To serve static files  TEMPLATE_DIRS Template directories Using settings in Python code from django.conf import settings if settings.DEBUG: # Do something 8
  • 9. Project / Site Creation  Creating new Project  django-admin.py startproject demoproject A project is a collection of applications  Creating new Application  python manage.py startapp demosite An application tries to provide a single, relatively self-contained set of related functions  Using the built-in web server  python manage.py runserver  python manage.py runserver 80 Runs by default at port 8000 It checks for any error and validate the models. Throws errors/warnings for any misconfigurations and invalid entries. 9
  • 10. URL Dispatcher / Patterns  Root URL should be configured in settings.py o  ROOT_URLCONF = 'app.urls' Syntax patterns(prefix, (regular expression, Python callback function [, optional dictionary [, optional name]]) ) Example: urlpatterns = patterns(' ', (r'^articles-year/$', 'mysite.news.views.articles_year'), ) Note: o No need to add a leading slash (/articles-year) o The 'r' in front of each regular expression string is optional but recommended. It tells Python that a string is "raw" -- that nothing in the string should be escaped. In python, the ‘’ backslash character in control chars must be escaped for regular expression use. Basically we have to add one more slash i.e t, b. To work around backslash plague, you can raw string, by prefixing the string with the letter r. 10
  • 11.  Can include other URLconf modules urlpatterns = patterns(' ', url(r'^support/', include('demoproject.support.urls')), )  Using Prefix urlpatterns = patterns(' ', (r'^articles/(d{4})/$', 'mysite.news.views.articles_year'), (r'^articles/(d{4})/(d{2})/$', 'mysite.news.views.articles_month'), ) Here mysite.news.views is common, so can be rewritten as follows urlpatterns = patterns('mysite.news.views', (r'^articles/(d{4})/$', 'articles_year'), (r'^articles/(d{4})/(d{2})/$', 'articles_month'), )  Passing extra arguments and Dictionary mapping patterns(' ', (r'^articles/(?P<year>d{4})/$', 'articles_year'), {'foo': 'bar'}), ) We can get the values in views.py as year='2005', foo='bar' 11
  • 12. Who uses Django?  BitBucket  DISQUS (serving 400 million people)  Pinterest  Instagram  dPaste  Mozilla (support.mozill, addons.mozilla)  NASA  PBS (Public Broadcasting Service)  The Washington Post, NY Times, LA Times, The Guardian  National Geographic, Discovery Channel 12