SlideShare a Scribd company logo
1 of 28
Nagireddy A
9666674234.
Python
Django Introduction
• Why python?
• Python is a a free and open-source programming language.
• It supports both functional and object oriented programming
• It is well suited for MVC development
• It has extensive documentation.
• It has wide range of community support.
• It has large standard library of modules
• It supports wide range of web-servers.
• It has clean and elegant syntax
Python Web Development with Django
• Django web framework is a free and open-source web framework written
in python programming language.
• It is used to develop web-applications
• It follows the model-view-template (MVT) architectural pattern.
• Primary goal of django is to simplify the creation of comple, database-driven websites.
• Django focuses on re-usability and "pluggability" of components, rapid development, and
the principle of don't repeat yourself.
• Include a detailed, colorful syllabus for parents to take home.
• Suggest ways that parents can help their child learn, such as reading together for 20
minutes a day.
• Use more than one slide to cover this information.
Why django ?
• It encourages big, tightly-coupled apps.
• It has Object Relational Mapper(ORM)
• It has clean URL design
• It has Multi lingual support
• It has both Template and Text filtering Engine
• Form generation and validation API
• An extensible authorization system
• A caching system for speeding up performance of applications
• A feed framework for generating RSS feeds
Advantages
Not the best for small projects
List of websites developed with Django
• Pinterest
• he Onion
• Instagram
• Disqus
• Spotify
• Mahalo
• Washington Post
• Firefox
• NASA
Disadvantages
• Object-relational mapper
• Define your data models entirely in Python. You get a rich, dynamic
database-access API for free — but you can still write SQL if needed
• Queries Ex: Filter, (Post.objects.filter(author=me) )
• get,( me = User.objects.get(username='ola'))
• __starts with,
• Orderbydate
• Polls.objects.all()
Django ORM
• A clean, elegant URL scheme is an important detail in a high-quality Web
application. Django encourages beautiful URL design and doesn’t put any
cruft in URLs, like .php or .asp.
• To design URLs for an application, you create a Python module called a
URLconf. Like a table of contents for your app, it contains a simple mapping
between URL patterns and your views.
• Templates
• Django’s template language is designed to strike a balance between power
and ease. It’s designed to feel comfortable and easy-to-learn to those used to
working with HTML, like designers and front-end developers. But it is also
flexible and highly extensible, allowing developers to augment the template
language as needed
URLs and views
• Forms
• Django provides a powerful form library that handles rendering forms as
HTML, validating user-submitted data, and converting that data to native
Python types. Django also provides a way to generate forms from your
existing models and use those forms to create and update data.
• Authentication
• Django comes with a full-featured and secure authentication system. It
handles user accounts, groups, permissions and cookie-based user sessions.
This lets you easily build sites that let users to create accounts and safely log
in/out.
• from django.contrib.auth.decorators import login_required
• from django.shortcuts import render
• Ex:(@login_required)
Admin
• One of the most powerful parts of Django is its automatic admin interface. It
reads metadata in your models to provide a powerful and production-ready
interface that content producers can immediately use to start managing
content on your site. It’s easy to set up and provides many hooks for
customization.
Internationalization
• Django offers full support for translating text into different languages, plus
locale-specific formatting of dates, times, numbers and time zones. It lets
developers and template authors specify which parts of their apps should
translated or formatted for local languages and cultures, and it uses these
hooks to localize Web applications for particular users according to their
preferences.
• from django.shortcuts import render
• from django.utils.translation import ugettext
• Django provides multiple protections against:
• Clickjacking
• Cross-site scripting
• Cross Site Request Forgery (CSRF)
• SQL injection
• Remote code execution
Security
• Browser
• Server
• Django
Django request lifecycle
• We can divide the request life cycle of the django application into
three layers.
1. Browser
2. Server
3. Django
Browser:
• Browser(client) is responsible for sending data to the server and also
responsible for receiving the response back.
Request life cycle
• It receives the request from the browser, based on the request it gives response back. If we take an example of
NGINX server. It can handle the 10,000 requests in a second based on the resources of the server(RAM,
Processor).
• If it receives more than 10,000 requests in a second it creates another process to handle it.
• We can divide request resources in two types.
• 1. static resource
• 2. dynamic resource(It has to process the data based on request to provide resource)
• If browser request for the static resources like images/css/javascript/etc, then NGINX serves the request without
sending it to the uWSGI server.
• If browser requests for a dynamic request then NGINX passes it to the uWSGI to process the request.
• At this stage NGINX acts like a reverse proxy server. A reverse proxy server is a type of proxy server that typically
sits behind the firewall in a private network and directs browser/client requests to the appropriate back-end
server(uWSGI).
• Advantages of reverse proxy server are Load balancing, Web acceleration, Security and anonymity
2. Server:
• Django layer comes into the picture when request passed from nGINX to the uWSGI it takes
the request middlewares from the settings and applies on the request to modify request.
• After applying the request middlewares it sends the request to url dispatcher. Url dispatcher is responsible
for dispatching the request to a view based on the url pattern
• Here we implement the business logic. We access the database resources by writing Django Queries.
• The query passes to the ORM(Object Relation Mapper). ORM converts the django query into
SQL(Structured Query Language) query and hits the database (MySQL/Postgres,etc). Database returns the
query results in a relational table. ORM again converts these relational data into django queryset and
returns back to the view.
• View passes the context(data that's retrieved from the database) to the template.
• Template renders the content with context data and forms the Response(HTML/XML/JSON/etc.)
• Again response middlewares which are defined in settings will apply and modifies the request and sends
the response to the Browser(Client).
3. Django
• Let's start our Django application from the beginning. To start our first
application we have to follow the below steps. Before going to start
our project learn about django project layout.
• Create a directory with your project name & change your directory to
the project. Lets consider our project as "Library Management“
mkdir Library && cd Library
Using Pip YOU can Install Any .py packages in python34/Scripts folder
• pip install Django==1.8.2
Start creating Project
• What is URL ?
Everybody say's that URL means "Uniform Resource Locator" . But
nobody understands it's meaning. But, now you will know
Uniform: remaining the same in all cases and at all times
Resource: any asset that can be consumable(in our case it's a webpage)
Locator: anything that helps us to find a resource (in our case it's a web-
address )
Types of URLS and using named URLS
- Django
• The content in static url cannot change with-respect to time.
Examples:
* Contact us page
* About Us etc.
Advantages using static URL ?
• search engines indexes static urls more quickly than the dynamic urls.
what is dynamic URL ?
• The content in static url changes with-respect to time.
* This kind of urls mostly used in e-commerce kinds of websites.
What is static URL ?
• What is SEO(Search Engine Optimization) ?
• Search engines crawls/downloads the contents of webpages through URL's.
• It stores our content and url to improve their search results.
• Search engine helps web user to find our web contents by indexing urls.
• Why we use named urls in Django ?
• Many of us use hard coded urls if we do not have idea of named urls.
• In some cases we have to change the urls. In this kinds of situations we have to find
old url and replace it in all templates/html files.
• By using named urls we can avoid it and if we change old url with new-one in
file that will automatically generates the url with new url.
• Note:
https://docs.djangoproject.com/en/1.10/topics/http/urls/
https://docs.djangoproject.com/en/1.10/ref/urlresolvers/#django.urls.reverse
Django templates and static files
Django templates:
Django templates are just HTML files. Django
creates HttpResponse for a request by
rendering the given template(HTML file) with
given context data.
Django supports different types of template
engines like JINJA, GENSHI, MAKO etc., Django also have it's
own template engines. Template engines are configured
with "TEMPLATES" setting. It contains a list of template engines.
Each template engine settings are defined in dictionary like
below.
We can observe in above configuration is that it contains a template engine(dictionary of settings)
inside a list.
BACKEND:
• It is a python path to a template engine class. It is used for rendering the templates.
• Django has two built-in template engines.
• django.template.backends.django.DjangoTemplates
• django.template.backends.jinja2.Jinja2
• Both backends works fine, but they differ in template language syntax. DIRS:
We provide "template path" to template engine. It will search for template with given path in directories
(APP_DIRS, DIRS). It considers the apps from
"INSTALLED_APPS" configuration.
• APP_DIRS:
• By default it is set to "True". This allow template engine to look for template in applications
template directories.
• OPTIONS:
• It allows us to define options like template context processors, template loaders.
Static files, the term "static" itself tells that they do not change with time.
Usually static files includes javascript, css, images, etc.
Configuration for static files
1.Make sure that
2.django.contrib.staticfiles is included in your
INSTALLED_APPS
2.Define STATIC_URL = '/static/' in settings.py file.
3.By default django finds the static files in "static" directory under apps or in root directory.
4.If you want to specify other directories as "static" you should add below configurations to
settings.py file
Django static files:
Django Project Architecture
• Let's talk about "Django" project structure in depth. You can see the complete
project layout in above image.
base/project/: It is a container for our project. we can give any name
to this directory and we can modify it at any time.
project/manage.py: It is created for all django projects. It is a command-
line utility, it is used to interact with the "django" project in many ways.
We use below command to run development server
• Python manage.py runserver
runserver" is a command which is used to run the server.
To show all available commands run the below command
Python manage.py --
project/project: This directory contains the project files.
project/project/__init__.py: It is a empty file that tells python to consider the
directory as a package.
project/project/settings.py: It contains all configuration settings like
database settings, installed apps, root url conf etc.
project/project/urls.py: It is the root url file. It contains url patterns to
map the request to the respective view to process it.
project/project/uwsgi.py: An entry-point for WSGI-compatible web
servers to serve our project.
project/static: It contains the static assets like css, javascript, images, etc.
project/templates: It contains the html files that will be used to create
http response to a request.
project/media: It is a path to store the media contents like files that are
uploaded by users.
To get project structure that is shown in above image. we need to
settings.py file with below code. To know more about customizing
settings visit: https://docs.djangoproject.com/en/1.10/ref/settings/
• project/app1: It is a python package, It contains application related files.
project/app1/templatetags: It's a directory that contains template tags of our
application. Template tags helps us at the time of rendering the template. It
takes the context from the template and processes it and again return it to
the template.
project/app1/templatetags/__init__.py: It's empty python file, it tells python
to recognize the directory as a python package.
project/app1/templatetags/tags.py: It's a python file, it contains the custom
template tags that we will use it in templates.
project/app1/apps.py: It contains the application's configuration.
project/app1/models.py: It contains the models(db tables) of application. we
represent our database tables with the model in django. ORM(Object
Mapper) converts the models to db tables. We do not use raw
Query Language) to query the database, instead we use django queries.
convert these queries into SQL equivalent code and performs the db query
and again converts the relational data to python objects to make things
easier
• project/app1/migrations: It contains the database migrations of application,
each migration contains the database schema related code.
project/app1/migrations/__init__.py: It's empty python file, it tells python to
recognize the directory as a python package.
project/app1/migrations/001_initial.py: It's a migration file of application. It
contains the database schema related code, that is used to create database
schema.
project/app1/__init__.py: It's a python file, it tells python to recognize the
directory as a python package.
project/app1/admin.py: Django provides the inbuilt admin panel. This file
contains the admin related code.
project/app1/urls.py: It contains url's that are related to the application.
project/app1/views.py: It contains the views(functions/classes) that are
mapped from the url's to process the request.
project/app1/tests.py: It contains the unit tests of the application.
Django Project Level operations for Apps:
• Django-admin start project Mysite
• Python manage.py startapp polls
• Python manage.py runserver
• Python manage.py test.py
• Python manage.py collectstatic
• Python manage.py compilemessages
• Python manage.py makemigrations
• Python manage.py migrate
• Python manage.py createsuperuser|changepassword|loaddata
Thank You

More Related Content

What's hot

Haxe React architecture and workflow
Haxe React architecture and workflowHaxe React architecture and workflow
Haxe React architecture and workflowPhilippe Elsass
 
Being RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceBeing RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceDavid Hoerster
 
Realtime Apps with Django
Realtime Apps with DjangoRealtime Apps with Django
Realtime Apps with DjangoRenyi Khor
 
Portal and Intranets
Portal and Intranets Portal and Intranets
Portal and Intranets Redar Ismail
 
Engineering the New LinkedIn Profile
Engineering the New LinkedIn ProfileEngineering the New LinkedIn Profile
Engineering the New LinkedIn ProfileJosh Clemm
 
eZ Find workshop: advanced insights & recipes
eZ Find workshop: advanced insights & recipeseZ Find workshop: advanced insights & recipes
eZ Find workshop: advanced insights & recipesPaul Borgermans
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationAndrew Siemer
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013Gavin Hogan
 
Drupal is not your Website
Drupal is not your Website Drupal is not your Website
Drupal is not your Website Phase2
 
Implementing Site Search in CQ5 / AEM
Implementing Site Search in CQ5 / AEMImplementing Site Search in CQ5 / AEM
Implementing Site Search in CQ5 / AEMrtpaem
 

What's hot (13)

Haxe React architecture and workflow
Haxe React architecture and workflowHaxe React architecture and workflow
Haxe React architecture and workflow
 
Being RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceBeing RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data Persistence
 
Realtime Apps with Django
Realtime Apps with DjangoRealtime Apps with Django
Realtime Apps with Django
 
Portal and Intranets
Portal and Intranets Portal and Intranets
Portal and Intranets
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Engineering the New LinkedIn Profile
Engineering the New LinkedIn ProfileEngineering the New LinkedIn Profile
Engineering the New LinkedIn Profile
 
eZ Find workshop: advanced insights & recipes
eZ Find workshop: advanced insights & recipeseZ Find workshop: advanced insights & recipes
eZ Find workshop: advanced insights & recipes
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Free django
Free djangoFree django
Free django
 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregation
 
Introduction to Grails 2013
Introduction to Grails 2013Introduction to Grails 2013
Introduction to Grails 2013
 
Drupal is not your Website
Drupal is not your Website Drupal is not your Website
Drupal is not your Website
 
Implementing Site Search in CQ5 / AEM
Implementing Site Search in CQ5 / AEMImplementing Site Search in CQ5 / AEM
Implementing Site Search in CQ5 / AEM
 

Similar to Django course

Unleash-the-power-of-Django.pptx
Unleash-the-power-of-Django.pptxUnleash-the-power-of-Django.pptx
Unleash-the-power-of-Django.pptxShivamSv1
 
What are the basic key points to focus on while learning Full-stack web devel...
What are the basic key points to focus on while learning Full-stack web devel...What are the basic key points to focus on while learning Full-stack web devel...
What are the basic key points to focus on while learning Full-stack web devel...kzayra69
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| EdurekaEdureka!
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docxfantabulous2024
 
Concepts and applications of Django.pptx
Concepts and applications of Django.pptxConcepts and applications of Django.pptx
Concepts and applications of Django.pptxsushmitjivtode4
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and ArchitectureAndolasoft Inc
 
What is Django Technology and How is it Used
What is Django Technology and How is it UsedWhat is Django Technology and How is it Used
What is Django Technology and How is it UsedRiyaBhardwaj51
 
Learn Django Tips, Tricks & Techniques for Developers
Learn Django Tips, Tricks & Techniques for DevelopersLearn Django Tips, Tricks & Techniques for Developers
Learn Django Tips, Tricks & Techniques for DevelopersMars Devs
 
python full stack course in hyderabad...
python full stack course in hyderabad...python full stack course in hyderabad...
python full stack course in hyderabad...sowmyavibhin
 
python full stack course in hyderabad...
python full stack course in hyderabad...python full stack course in hyderabad...
python full stack course in hyderabad...sowmyavibhin
 
Web frameworks in python
Web frameworks in pythonWeb frameworks in python
Web frameworks in pythonKnowledgehut
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoKnoldus Inc.
 
Swagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlierSwagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlierMiroslav Resetar
 

Similar to Django course (20)

Python & Django
Python & DjangoPython & Django
Python & Django
 
Unleash-the-power-of-Django.pptx
Unleash-the-power-of-Django.pptxUnleash-the-power-of-Django.pptx
Unleash-the-power-of-Django.pptx
 
What are the basic key points to focus on while learning Full-stack web devel...
What are the basic key points to focus on while learning Full-stack web devel...What are the basic key points to focus on while learning Full-stack web devel...
What are the basic key points to focus on while learning Full-stack web devel...
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| Edureka
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
 
Concepts and applications of Django.pptx
Concepts and applications of Django.pptxConcepts and applications of Django.pptx
Concepts and applications of Django.pptx
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and Architecture
 
Django
DjangoDjango
Django
 
Django PPT.pptx
Django PPT.pptxDjango PPT.pptx
Django PPT.pptx
 
What is Django Technology and How is it Used
What is Django Technology and How is it UsedWhat is Django Technology and How is it Used
What is Django Technology and How is it Used
 
Learn Django Tips, Tricks & Techniques for Developers
Learn Django Tips, Tricks & Techniques for DevelopersLearn Django Tips, Tricks & Techniques for Developers
Learn Django Tips, Tricks & Techniques for Developers
 
python full stack course in hyderabad...
python full stack course in hyderabad...python full stack course in hyderabad...
python full stack course in hyderabad...
 
python full stack course in hyderabad...
python full stack course in hyderabad...python full stack course in hyderabad...
python full stack course in hyderabad...
 
Web frameworks in python
Web frameworks in pythonWeb frameworks in python
Web frameworks in python
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django Girls Tutorial
Django Girls TutorialDjango Girls Tutorial
Django Girls Tutorial
 
Top java script frameworks ppt
Top java script frameworks pptTop java script frameworks ppt
Top java script frameworks ppt
 
Django
DjangoDjango
Django
 
Swagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlierSwagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlier
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
 

Recently uploaded

VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackVIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackSuhani Kapoor
 
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big BoodyDubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boodykojalkojal131
 
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...Suhani Kapoor
 
Preventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxPreventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxGry Tina Tinde
 
Delhi Call Girls South Delhi 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls South Delhi 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls South Delhi 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls South Delhi 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
Call Girl in Low Price Delhi Punjabi Bagh  9711199012Call Girl in Low Price Delhi Punjabi Bagh  9711199012
Call Girl in Low Price Delhi Punjabi Bagh 9711199012sapnasaifi408
 
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证女王大学硕士毕业证成绩单(加急办理)认证海外毕业证
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证obuhobo
 
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳anilsa9823
 
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service CuttackVIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service CuttackSuhani Kapoor
 
PM Job Search Council Info Session - PMI Silver Spring Chapter
PM Job Search Council Info Session - PMI Silver Spring ChapterPM Job Search Council Info Session - PMI Silver Spring Chapter
PM Job Search Council Info Session - PMI Silver Spring ChapterHector Del Castillo, CPM, CPMM
 
Vip Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
Vip  Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...Vip  Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
Vip Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...shivangimorya083
 
Internshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University CertificateInternshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University CertificateSoham Mondal
 
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...Suhani Kapoor
 
Production Day 1.pptxjvjbvbcbcb bj bvcbj
Production Day 1.pptxjvjbvbcbcb bj bvcbjProduction Day 1.pptxjvjbvbcbcb bj bvcbj
Production Day 1.pptxjvjbvbcbcb bj bvcbjLewisJB
 
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...Suhani Kapoor
 
Low Rate Call Girls Gorakhpur Anika 8250192130 Independent Escort Service Gor...
Low Rate Call Girls Gorakhpur Anika 8250192130 Independent Escort Service Gor...Low Rate Call Girls Gorakhpur Anika 8250192130 Independent Escort Service Gor...
Low Rate Call Girls Gorakhpur Anika 8250192130 Independent Escort Service Gor...Suhani Kapoor
 
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士obuhobo
 
VIP Call Girl Bhiwandi Aashi 8250192130 Independent Escort Service Bhiwandi
VIP Call Girl Bhiwandi Aashi 8250192130 Independent Escort Service BhiwandiVIP Call Girl Bhiwandi Aashi 8250192130 Independent Escort Service Bhiwandi
VIP Call Girl Bhiwandi Aashi 8250192130 Independent Escort Service BhiwandiSuhani Kapoor
 
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...shivangimorya083
 

Recently uploaded (20)

VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackVIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
 
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big BoodyDubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
Dubai Call Girls Demons O525547819 Call Girls IN DUbai Natural Big Boody
 
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
VIP Call Girls in Jamshedpur Aarohi 8250192130 Independent Escort Service Jam...
 
Preventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptxPreventing and ending sexual harassment in the workplace.pptx
Preventing and ending sexual harassment in the workplace.pptx
 
Delhi Call Girls South Delhi 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls South Delhi 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls South Delhi 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls South Delhi 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
Call Girl in Low Price Delhi Punjabi Bagh  9711199012Call Girl in Low Price Delhi Punjabi Bagh  9711199012
Call Girl in Low Price Delhi Punjabi Bagh 9711199012
 
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证女王大学硕士毕业证成绩单(加急办理)认证海外毕业证
女王大学硕士毕业证成绩单(加急办理)认证海外毕业证
 
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service  🧳
CALL ON ➥8923113531 🔝Call Girls Husainganj Lucknow best Female service 🧳
 
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service CuttackVIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
VIP Call Girls in Cuttack Aarohi 8250192130 Independent Escort Service Cuttack
 
PM Job Search Council Info Session - PMI Silver Spring Chapter
PM Job Search Council Info Session - PMI Silver Spring ChapterPM Job Search Council Info Session - PMI Silver Spring Chapter
PM Job Search Council Info Session - PMI Silver Spring Chapter
 
Vip Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
Vip  Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...Vip  Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
Vip Modals Call Girls (Delhi) Rohini 9711199171✔️ Full night Service for one...
 
Internshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University CertificateInternshala Student Partner 6.0 Jadavpur University Certificate
Internshala Student Partner 6.0 Jadavpur University Certificate
 
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
VIP Call Girls Firozabad Aaradhya 8250192130 Independent Escort Service Firoz...
 
Production Day 1.pptxjvjbvbcbcb bj bvcbj
Production Day 1.pptxjvjbvbcbcb bj bvcbjProduction Day 1.pptxjvjbvbcbcb bj bvcbj
Production Day 1.pptxjvjbvbcbcb bj bvcbj
 
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
VIP Russian Call Girls in Amravati Deepika 8250192130 Independent Escort Serv...
 
Low Rate Call Girls Gorakhpur Anika 8250192130 Independent Escort Service Gor...
Low Rate Call Girls Gorakhpur Anika 8250192130 Independent Escort Service Gor...Low Rate Call Girls Gorakhpur Anika 8250192130 Independent Escort Service Gor...
Low Rate Call Girls Gorakhpur Anika 8250192130 Independent Escort Service Gor...
 
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCeCall Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
 
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
内布拉斯加大学林肯分校毕业证录取书( 退学 )学位证书硕士
 
VIP Call Girl Bhiwandi Aashi 8250192130 Independent Escort Service Bhiwandi
VIP Call Girl Bhiwandi Aashi 8250192130 Independent Escort Service BhiwandiVIP Call Girl Bhiwandi Aashi 8250192130 Independent Escort Service Bhiwandi
VIP Call Girl Bhiwandi Aashi 8250192130 Independent Escort Service Bhiwandi
 
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
 

Django course

  • 2. • Why python? • Python is a a free and open-source programming language. • It supports both functional and object oriented programming • It is well suited for MVC development • It has extensive documentation. • It has wide range of community support. • It has large standard library of modules • It supports wide range of web-servers. • It has clean and elegant syntax Python Web Development with Django
  • 3. • Django web framework is a free and open-source web framework written in python programming language. • It is used to develop web-applications • It follows the model-view-template (MVT) architectural pattern. • Primary goal of django is to simplify the creation of comple, database-driven websites. • Django focuses on re-usability and "pluggability" of components, rapid development, and the principle of don't repeat yourself. • Include a detailed, colorful syllabus for parents to take home. • Suggest ways that parents can help their child learn, such as reading together for 20 minutes a day. • Use more than one slide to cover this information. Why django ?
  • 4. • It encourages big, tightly-coupled apps. • It has Object Relational Mapper(ORM) • It has clean URL design • It has Multi lingual support • It has both Template and Text filtering Engine • Form generation and validation API • An extensible authorization system • A caching system for speeding up performance of applications • A feed framework for generating RSS feeds Advantages
  • 5. Not the best for small projects List of websites developed with Django • Pinterest • he Onion • Instagram • Disqus • Spotify • Mahalo • Washington Post • Firefox • NASA Disadvantages
  • 6. • Object-relational mapper • Define your data models entirely in Python. You get a rich, dynamic database-access API for free — but you can still write SQL if needed • Queries Ex: Filter, (Post.objects.filter(author=me) ) • get,( me = User.objects.get(username='ola')) • __starts with, • Orderbydate • Polls.objects.all() Django ORM
  • 7. • A clean, elegant URL scheme is an important detail in a high-quality Web application. Django encourages beautiful URL design and doesn’t put any cruft in URLs, like .php or .asp. • To design URLs for an application, you create a Python module called a URLconf. Like a table of contents for your app, it contains a simple mapping between URL patterns and your views. • Templates • Django’s template language is designed to strike a balance between power and ease. It’s designed to feel comfortable and easy-to-learn to those used to working with HTML, like designers and front-end developers. But it is also flexible and highly extensible, allowing developers to augment the template language as needed URLs and views
  • 8. • Forms • Django provides a powerful form library that handles rendering forms as HTML, validating user-submitted data, and converting that data to native Python types. Django also provides a way to generate forms from your existing models and use those forms to create and update data. • Authentication • Django comes with a full-featured and secure authentication system. It handles user accounts, groups, permissions and cookie-based user sessions. This lets you easily build sites that let users to create accounts and safely log in/out. • from django.contrib.auth.decorators import login_required • from django.shortcuts import render • Ex:(@login_required)
  • 9. Admin • One of the most powerful parts of Django is its automatic admin interface. It reads metadata in your models to provide a powerful and production-ready interface that content producers can immediately use to start managing content on your site. It’s easy to set up and provides many hooks for customization. Internationalization • Django offers full support for translating text into different languages, plus locale-specific formatting of dates, times, numbers and time zones. It lets developers and template authors specify which parts of their apps should translated or formatted for local languages and cultures, and it uses these hooks to localize Web applications for particular users according to their preferences. • from django.shortcuts import render • from django.utils.translation import ugettext
  • 10. • Django provides multiple protections against: • Clickjacking • Cross-site scripting • Cross Site Request Forgery (CSRF) • SQL injection • Remote code execution Security
  • 11. • Browser • Server • Django Django request lifecycle
  • 12. • We can divide the request life cycle of the django application into three layers. 1. Browser 2. Server 3. Django Browser: • Browser(client) is responsible for sending data to the server and also responsible for receiving the response back. Request life cycle
  • 13. • It receives the request from the browser, based on the request it gives response back. If we take an example of NGINX server. It can handle the 10,000 requests in a second based on the resources of the server(RAM, Processor). • If it receives more than 10,000 requests in a second it creates another process to handle it. • We can divide request resources in two types. • 1. static resource • 2. dynamic resource(It has to process the data based on request to provide resource) • If browser request for the static resources like images/css/javascript/etc, then NGINX serves the request without sending it to the uWSGI server. • If browser requests for a dynamic request then NGINX passes it to the uWSGI to process the request. • At this stage NGINX acts like a reverse proxy server. A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs browser/client requests to the appropriate back-end server(uWSGI). • Advantages of reverse proxy server are Load balancing, Web acceleration, Security and anonymity 2. Server:
  • 14. • Django layer comes into the picture when request passed from nGINX to the uWSGI it takes the request middlewares from the settings and applies on the request to modify request. • After applying the request middlewares it sends the request to url dispatcher. Url dispatcher is responsible for dispatching the request to a view based on the url pattern • Here we implement the business logic. We access the database resources by writing Django Queries. • The query passes to the ORM(Object Relation Mapper). ORM converts the django query into SQL(Structured Query Language) query and hits the database (MySQL/Postgres,etc). Database returns the query results in a relational table. ORM again converts these relational data into django queryset and returns back to the view. • View passes the context(data that's retrieved from the database) to the template. • Template renders the content with context data and forms the Response(HTML/XML/JSON/etc.) • Again response middlewares which are defined in settings will apply and modifies the request and sends the response to the Browser(Client). 3. Django
  • 15. • Let's start our Django application from the beginning. To start our first application we have to follow the below steps. Before going to start our project learn about django project layout. • Create a directory with your project name & change your directory to the project. Lets consider our project as "Library Management“ mkdir Library && cd Library Using Pip YOU can Install Any .py packages in python34/Scripts folder • pip install Django==1.8.2 Start creating Project
  • 16. • What is URL ? Everybody say's that URL means "Uniform Resource Locator" . But nobody understands it's meaning. But, now you will know Uniform: remaining the same in all cases and at all times Resource: any asset that can be consumable(in our case it's a webpage) Locator: anything that helps us to find a resource (in our case it's a web- address ) Types of URLS and using named URLS - Django
  • 17. • The content in static url cannot change with-respect to time. Examples: * Contact us page * About Us etc. Advantages using static URL ? • search engines indexes static urls more quickly than the dynamic urls. what is dynamic URL ? • The content in static url changes with-respect to time. * This kind of urls mostly used in e-commerce kinds of websites. What is static URL ?
  • 18. • What is SEO(Search Engine Optimization) ? • Search engines crawls/downloads the contents of webpages through URL's. • It stores our content and url to improve their search results. • Search engine helps web user to find our web contents by indexing urls. • Why we use named urls in Django ? • Many of us use hard coded urls if we do not have idea of named urls. • In some cases we have to change the urls. In this kinds of situations we have to find old url and replace it in all templates/html files. • By using named urls we can avoid it and if we change old url with new-one in file that will automatically generates the url with new url. • Note: https://docs.djangoproject.com/en/1.10/topics/http/urls/ https://docs.djangoproject.com/en/1.10/ref/urlresolvers/#django.urls.reverse
  • 19. Django templates and static files Django templates: Django templates are just HTML files. Django creates HttpResponse for a request by rendering the given template(HTML file) with given context data. Django supports different types of template engines like JINJA, GENSHI, MAKO etc., Django also have it's own template engines. Template engines are configured with "TEMPLATES" setting. It contains a list of template engines. Each template engine settings are defined in dictionary like below.
  • 20. We can observe in above configuration is that it contains a template engine(dictionary of settings) inside a list. BACKEND: • It is a python path to a template engine class. It is used for rendering the templates. • Django has two built-in template engines. • django.template.backends.django.DjangoTemplates • django.template.backends.jinja2.Jinja2 • Both backends works fine, but they differ in template language syntax. DIRS: We provide "template path" to template engine. It will search for template with given path in directories (APP_DIRS, DIRS). It considers the apps from "INSTALLED_APPS" configuration. • APP_DIRS: • By default it is set to "True". This allow template engine to look for template in applications template directories. • OPTIONS: • It allows us to define options like template context processors, template loaders.
  • 21. Static files, the term "static" itself tells that they do not change with time. Usually static files includes javascript, css, images, etc. Configuration for static files 1.Make sure that 2.django.contrib.staticfiles is included in your INSTALLED_APPS 2.Define STATIC_URL = '/static/' in settings.py file. 3.By default django finds the static files in "static" directory under apps or in root directory. 4.If you want to specify other directories as "static" you should add below configurations to settings.py file Django static files:
  • 23. • Let's talk about "Django" project structure in depth. You can see the complete project layout in above image. base/project/: It is a container for our project. we can give any name to this directory and we can modify it at any time. project/manage.py: It is created for all django projects. It is a command- line utility, it is used to interact with the "django" project in many ways. We use below command to run development server • Python manage.py runserver runserver" is a command which is used to run the server. To show all available commands run the below command Python manage.py -- project/project: This directory contains the project files. project/project/__init__.py: It is a empty file that tells python to consider the directory as a package.
  • 24. project/project/settings.py: It contains all configuration settings like database settings, installed apps, root url conf etc. project/project/urls.py: It is the root url file. It contains url patterns to map the request to the respective view to process it. project/project/uwsgi.py: An entry-point for WSGI-compatible web servers to serve our project. project/static: It contains the static assets like css, javascript, images, etc. project/templates: It contains the html files that will be used to create http response to a request. project/media: It is a path to store the media contents like files that are uploaded by users. To get project structure that is shown in above image. we need to settings.py file with below code. To know more about customizing settings visit: https://docs.djangoproject.com/en/1.10/ref/settings/
  • 25. • project/app1: It is a python package, It contains application related files. project/app1/templatetags: It's a directory that contains template tags of our application. Template tags helps us at the time of rendering the template. It takes the context from the template and processes it and again return it to the template. project/app1/templatetags/__init__.py: It's empty python file, it tells python to recognize the directory as a python package. project/app1/templatetags/tags.py: It's a python file, it contains the custom template tags that we will use it in templates. project/app1/apps.py: It contains the application's configuration. project/app1/models.py: It contains the models(db tables) of application. we represent our database tables with the model in django. ORM(Object Mapper) converts the models to db tables. We do not use raw Query Language) to query the database, instead we use django queries. convert these queries into SQL equivalent code and performs the db query and again converts the relational data to python objects to make things easier
  • 26. • project/app1/migrations: It contains the database migrations of application, each migration contains the database schema related code. project/app1/migrations/__init__.py: It's empty python file, it tells python to recognize the directory as a python package. project/app1/migrations/001_initial.py: It's a migration file of application. It contains the database schema related code, that is used to create database schema. project/app1/__init__.py: It's a python file, it tells python to recognize the directory as a python package. project/app1/admin.py: Django provides the inbuilt admin panel. This file contains the admin related code. project/app1/urls.py: It contains url's that are related to the application. project/app1/views.py: It contains the views(functions/classes) that are mapped from the url's to process the request. project/app1/tests.py: It contains the unit tests of the application.
  • 27. Django Project Level operations for Apps: • Django-admin start project Mysite • Python manage.py startapp polls • Python manage.py runserver • Python manage.py test.py • Python manage.py collectstatic • Python manage.py compilemessages • Python manage.py makemigrations • Python manage.py migrate • Python manage.py createsuperuser|changepassword|loaddata