SlideShare une entreprise Scribd logo
1  sur  46
A
SEMINAR
ON
Prepared by: Mr. Raviraj Solanki
Content
 What is Django?
 A brief history of Django
 DJANGOMVC - MVT Pattern
 Django – Environment
 Django – Creating a Project
 Django – Apps Life Cycle
 Django - Creating Views
 Workwith databsae in Djnago
 Pros of Django
 Cons of Django
 Conclusion
What is Djnago?
 is a free and open-source web framework,
written in Python, which follows the model-view-
template (MVT) architectural pattern.
 It is maintained by the Django Software
Foundation (DSF).
 Django is a high-level Python web framework
that encourages rapid development and clean,
pragmatic design.
 Django makes it easier to build better web apps
quickly and with less code.
History of Django
 2003: Started by Adrian Holovaty and Simon
Willison as an internal project at the Lawrence
Journal-World newspaper.
 2005: Released July 2005 and named it Django,
afterthe jazz guitarist Django Reinhardt.
 2005: Mature enough to handle several high-traffic
sites.
 Current: Django is now an open source project with
contributors across the world.
 Jean "Django"
Reinhardt was a
Belgian-born French
jazz guitarist and
composer of Romani
background, regarded
as one of the greatest
musicians of the
twentieth century,
having written nearly
100 songs,
Django – Design Philosophies
 Django comes with the following design philosophies:
 Loosely Coupled: Django aims to make each element of its stack
independent of the others.
 Less Coding: Less code so in turn a quick development.
 Don't Repeat Yourself (DRY): Everything should be developed only
in exactly one place instead of repeating it again and again.
 Fast Development: Django's philosophy is to do all it can to
facilitate hyper-fast development.
 Clean Design: Django strictly maintains a clean design throughout
its own code and makes it easy to follow best web-development
practices.
DJANGO MVC - MVT Pattern
 The Model-View-Template (MVT) is slightly
different from MVC.
 M= Model, The database interface
 V= View, Logic for getting stuff in and out of the
database
 T= Template, The display logic
 The template is a HTML file mixed with Django
Template Language (DTL).
The developer provides the Model, the view and the
template then just maps it to a URL and Django does the
magic to serve it to the user.
Django – Environment
 Step 1 – Installing Python
 Step 2 - Installing Django
 https://www.djangoproject.com/download/
 Step 3 – Database Setup
 Django supports several major database
engines and you can set up any of them based
on your comfort.
 MySQL
 PostgreSQL
 SQLite 3
 Oracle
 MongoDb
 GoogleAppEngine Datastore
 Step 4 – Web Server
 Django comes with a lightweight web serverfor
developing and testing applications.
 This serveris pre-configured to workwith Django,
and more importantly, it restarts wheneveryou
modify the code.
Django – Creating a Project
 In Django, every web app you want to create is
called a project; and a project is a sum of
applications.
 An application is a set of code files relying on the
MVT pattern.
 As example let's say we want to build a website,
the website is our project and, the forum, news,
contact engine are applications.
 A project is a collection of configuration and apps
for a particular website.
 A project can contain multiple apps.
 An app can be in multiple projects.
Create a Project
 Whether you are on Windows or Linux, just get a
terminal or a cmd prompt and navigate to the place
you want yourproject to be created, then use this
code:
 $ django-admin startproject myproject
 This will create a "myproject" folder with the following
structure:
 myproject/
 manage.py
 myproject/
 __init__.py
 settings.py
 urls.py
 wsgi.py
The Project Structure
 The “myproject” folder is just your project
container, it actually contains two elements:
 manage.py: This file is kind of your project local
django-admin for interacting with your project via
command line (start the development server,
sync db...). To get a full list of command
accessible via manage.py you can use the code:
 $ python manage.py help
 The “myproject” subfolder: This folder is the actual
python package of your project. It contains four
files:
 __init__.py: Just for python, treat this folder as
package.
 settings.py: As the name indicates, your project
settings.
 urls.py: All links of your project and the function to
call.
 wsgi.py: If you need to deploy your project over
Web ServerGateway Interface (WSGI).
Django also supports:
 MySQL (django.db.backends.mysql)
 PostGreSQL
(django.db.backends.postgresql_psycopg2)
 Oracle (django.db.backends.oracle) and
NoSQL DB
 MongoDB(django_mongodb_engine)
 Now that your project is created and
configured make sure it's working:
 $ python manage.py runserver
Django – Apps Life Cycle
 Create an Application
 We assume you are in your project folder. In
our main “myproject” folder, the same folder
than manage.py:
 $ python manage.py startapp myapp
 You just created myapp application and like project, Django
create a “myapp” folder with the application structure:
 myapp/
 __init__.py
 admin.py
 models.py
 tests.py
 views.py
 __init__.py: python handles this folder as a package.
 admin.py: This file helps you make the app modifiable in the
admin interface.
 models.py: This is where all the application models are stored.
 tests.py: This is where your unit tests are.
 views.py: This is where your application views are.
Changing the port & server’s IP
 By default, the runserver command starts the
development server on the internal IP at port
8000.
 If you want to change the server’s port, pass it as
a command-line argument. For instance, this
command starts the server on port 8080:
 $ python manage.py runserver8080
 If you want to change the server’s IP, pass it along
with the port. So to listen on all public IPs (useful if
you want to show off your work on other
computers on your network), use:
 $ python manage.py runserver0.0.0.0:8000
Django - Creating Views
 A view function, or “view” for short, is simply a
Python function that takes a web request and
returns a web response.
 This response can be the HTML contents of a
Web page, or a redirect, or a 404 error, or an
XML document, or an image, etc.
 Example: You use view to create web pages,
note that you need to associate a view to a URL
to see it as a web page.
 In Django, views have to be created in the app
views.py file.
Write yourfirst view
Open the file myapp/views.py and put the following
Python code in it:
myapp/views.py
fromdjango.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the
myapp index.")
•HttpResponse to renderthe HTML
•see this view as a page we just need to map it to a
URL
Call the view
 To call the view, we need to map it to a URL -
and for this we need a URLconf.
 To create a URLconf in the polls directory,
create a file called urls.py.
myapp/urls.py file include the following code:
myapp/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
 The next step is to point the root URLconf at the
myapp.urls module.
 In myproject/urls.py, add an import for
django.conf.urls.include and insert an include() in the
urlpatterns list, so you have:
myproject/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^myapp/', include(‘myapp.urls')),
url(r'^admin/', admin.site.urls),
]
Run
 Go to http://localhost:8000/myapp/in your
browser, and you should see the text
 “He llo , wo rld. Yo u’re at the m yapp inde x. ”,
which you defined in the index view.
 The url() function is passed four arguments,
two required: regex and view, and two
optional: kwargs, and name.
 When to use include()
 You should always use include()
when you include otherURL
patterns.
 admin.site.urls is the only exception
to this.
Templates in Django
 A template is just an HTML file, that contains the HTML
design of our website.
 A Django Template is a sequence of Text that helps in
separation of the presentation layer of a document from its
data.
 A template is simply a text file. It can generate any text-
based format (HTML, XML, CSV, etc.).
 A Django template is intended to separate the presentation
of a document from its data. A template defines
placeholders and various bits of basic logic (template tags)
that regulate how the document should be displayed.
Usually, templates are used for producing HTML.
Django – Template System
 Django makes it possible to separate python and HTML, the
python goes in views and HTML goes in templates. To link the
two, Django relies on the render function and the Django Template
language.
 The RenderFunction
 This function takes three parameters:
 Request: The initial request.
 The path to the template: This is the path relative to the
TEMPLATE_DIRS option in the project settings.py variables.
 Dictionary of parameters: A dictionary that contains all variables
needed in the template. This variable can be created or you can
use locals() to pass all local variable declared in the view.
Django Template Language
(DTL)
 Displaying Variables
 A variable looks like this: {{variable}}.
 The template replaces the variable by the variable sent by
the view in the third parameterof the renderfunction.
 Let's change our hello.html to display today’s date:
 Put .html file here (by default django use this
location)
 C:Python27Libsite-packagesDjango-1.10.5-
py2.7.eggdjangocontribadmintemplates
 After in myproject settings.py put this line
under TEMPLATES=[] (its show the above
path as base_dir)
 'DIRS': [os.path.join(BASE_DIR,'templates')],
Call the view forhtml
Create urls.py undermyapp dirs n put this
code.
fromdjango.conf.urls import url
from. import views
urlpatterns = [
url(' ',views.hello),
]
Map HTML with yourproject
 The next step is to point the root URLconf at the
myapp.urls module.
 In myproject/urls.py, add an import for
django.conf.urls.include and insert an include() in the
urlpatterns list, so you have:
myproject/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^myapp/', include(‘myapp.urls')),
url(r'^admin/', admin.site.urls),
]
Workwith databsae in Djnago
 Database setup
 open up myproject/settings.py.
 It’s a normal Python module with module-level
variables representing Django settings.
 By default, the configuration uses SQLite.
Creating Models
 define your models – essentially, your
database layout, with additional metadata.
 A model is a class that represents table or
collection in ourDB, and where every
attribute of the class is a field of the table or
collection.
 Models are defined in the app/models.py (in
ourexample: myapp/models.py)
steps
 Create models (data structure of our app)
 Set the full path of db in myproject/setting.py
 Set app name in installed_app
 Run manage.py migrate --run-syncdb for default
table creation.
 Create superuser (admin) using manage.py
createsuperuser
 Setting admin forregisterourmodel
 Checkthe structure in browser
Save this in myapp/models.py
fromdjango.db import models
# Create yourmodels here.
class BlogPost(models.Model):
title=models.CharField(max_length=150)
body=models.TextField()
timestamp=models.DateTimeField()
Setting admin forregisterour
model in myapp/admin.py
from django.contrib import admin
from myapp import models
admin.site.register(models.BlogPost)
 Before launching your server, to access your Admin
Interface, you need to initiate the database:
 python manage.py migrate --run-syncdb
 syncdb will create necessary tables orcollections
depending on yourdb type, necessary forthe admin
interface to run.
 Even if you don't have a superuser, you will be
prompted to create one.
 If you already have a superuser or have forgotten it,
you can always create one using the following code:
 $ python manage.py createsuperuser
Get the Project to Know About Your
Application
 At this stage we have our "myapp" application,
now we need to registerit with ourDjango
project "myproject".
 To do so, update INSTALLED_APPS tuple in the
settings.py file of your project (add your app
name):
 Now just run the server:
 $ python manage.py runserver
 And your admin interface is accessible at:
http://127.0.0.1:8000/admin/
Once connected with yoursuperuser
account, you will see the following screen:
 That interface will let you administrate Django groups and
users, and all registered models in your app.
 The interface gives you the ability to do at least the "CRUD"
(Create, Read, Update, Delete) operations on yourmodels.
Pros of Django
 Object-Relational Mapping (ORM) Support:
Django provides a bridge between the data
model and the database engine, and supports a
large set of database systems including MySQL,
Oracle, Postgres, etc.
 Multilingual Support: Django supports
multilingual websites through its built-in
internationalization system. So you can develop
your website, which would support multiple
languages.
 FrameworkSupport: Django has built-in support
for Ajax, RSS, Caching and various other
frameworks.
 Administration GUI: Django provides a nice
ready-to-use user interface for administrative
activities.
 Development Environment: Django comes with a
lightweight web server to facilitate end-to-end
application development and testing.
Cons of Django
 Not the best for small projects
 Heavy because we have to use the whole
django
 Less code but we have to manage lot of stuff.
 Configuration is more
 Required MVT
Who uses Django
 Pinterest
 Event brite
 Prezi
 Bitbucket
 Nasa offcial website
 Spotify
 Instagram
Django by rj
Django by rj

Contenu connexe

Tendances

Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC FrameworkBala Kumar
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to djangoIlian Iliev
 
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!
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django frameworkKnoldus Inc.
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
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 and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application StructureSEONGTAEK OH
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2fishwarter
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
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 DjangoChariza Pladin
 
Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...Zhe Li
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoAhmed Salama
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flaskjuzten
 

Tendances (20)

Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC Framework
 
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...
 
Django PPT.pptx
Django PPT.pptxDjango PPT.pptx
Django PPT.pptx
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django framework
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
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?
 
Flask
FlaskFlask
Flask
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application Structure
 
django
djangodjango
django
 
Django
DjangoDjango
Django
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
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
 
Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...
 
ORM in Django
ORM in DjangoORM in Django
ORM in Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flask
 

Similaire à Django by rj

بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگوrailsbootcamp
 
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
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and ArchitectureAndolasoft Inc
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem vAkash Rajguru
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docxfantabulous2024
 
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
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersRosario Renga
 
1-_Introduction_To_Django_Model_and_Database (1).pptx
1-_Introduction_To_Django_Model_and_Database (1).pptx1-_Introduction_To_Django_Model_and_Database (1).pptx
1-_Introduction_To_Django_Model_and_Database (1).pptxTamilGamers4
 
Django Article V0
Django Article V0Django Article V0
Django Article V0Udi Bauman
 
Django tutorial
Django tutorialDjango tutorial
Django tutorialKsd Che
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 
Django simplified : by weever mbakaya
Django simplified : by weever mbakayaDjango simplified : by weever mbakaya
Django simplified : by weever mbakayaMbakaya Kwatukha
 
Easy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Easy Step-by-Step Guide to Develop REST APIs with Django REST FrameworkEasy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Easy Step-by-Step Guide to Develop REST APIs with Django REST FrameworkInexture Solutions
 
Django framework
Django framework Django framework
Django framework TIB Academy
 

Similaire à Django by rj (20)

Django
DjangoDjango
Django
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
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)
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and Architecture
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem v
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
 
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
 
React django
React djangoReact django
React django
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
Django Introdcution
Django IntrodcutionDjango Introdcution
Django Introdcution
 
1-_Introduction_To_Django_Model_and_Database (1).pptx
1-_Introduction_To_Django_Model_and_Database (1).pptx1-_Introduction_To_Django_Model_and_Database (1).pptx
1-_Introduction_To_Django_Model_and_Database (1).pptx
 
Django Article V0
Django Article V0Django Article V0
Django Article V0
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
 
DJango
DJangoDJango
DJango
 
django
djangodjango
django
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Django simplified : by weever mbakaya
Django simplified : by weever mbakayaDjango simplified : by weever mbakaya
Django simplified : by weever mbakaya
 
Easy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Easy Step-by-Step Guide to Develop REST APIs with Django REST FrameworkEasy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Easy Step-by-Step Guide to Develop REST APIs with Django REST Framework
 
Django framework
Django framework Django framework
Django framework
 
Django
DjangoDjango
Django
 

Plus de Shree M.L.Kakadiya MCA mahila college, Amreli

Plus de Shree M.L.Kakadiya MCA mahila college, Amreli (20)

Machine Learning by Rj
Machine Learning by RjMachine Learning by Rj
Machine Learning by Rj
 
Listeners and filters in servlet
Listeners and filters in servletListeners and filters in servlet
Listeners and filters in servlet
 
Servlet unit 2
Servlet unit 2 Servlet unit 2
Servlet unit 2
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Research paper on python by Rj
Research paper on python by RjResearch paper on python by Rj
Research paper on python by Rj
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Motion capture by Rj
Motion capture by RjMotion capture by Rj
Motion capture by Rj
 
Research paper on big data and hadoop
Research paper on big data and hadoopResearch paper on big data and hadoop
Research paper on big data and hadoop
 
Text processing by Rj
Text processing by RjText processing by Rj
Text processing by Rj
 
Python and data analytics
Python and data analyticsPython and data analytics
Python and data analytics
 
Multithreading by rj
Multithreading by rjMultithreading by rj
Multithreading by rj
 
Database programming
Database programmingDatabase programming
Database programming
 
CGI by rj
CGI by rjCGI by rj
CGI by rj
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
Seminar on Project Management by Rj
Seminar on Project Management by RjSeminar on Project Management by Rj
Seminar on Project Management by Rj
 
Spring by rj
Spring by rjSpring by rj
Spring by rj
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 
Leadership & Motivation
Leadership & MotivationLeadership & Motivation
Leadership & Motivation
 
Event handling
Event handlingEvent handling
Event handling
 

Dernier

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 

Dernier (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

Django by rj

  • 2. Content  What is Django?  A brief history of Django  DJANGOMVC - MVT Pattern  Django – Environment  Django – Creating a Project  Django – Apps Life Cycle  Django - Creating Views  Workwith databsae in Djnago  Pros of Django  Cons of Django  Conclusion
  • 3. What is Djnago?  is a free and open-source web framework, written in Python, which follows the model-view- template (MVT) architectural pattern.  It is maintained by the Django Software Foundation (DSF).  Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design.  Django makes it easier to build better web apps quickly and with less code.
  • 4. History of Django  2003: Started by Adrian Holovaty and Simon Willison as an internal project at the Lawrence Journal-World newspaper.  2005: Released July 2005 and named it Django, afterthe jazz guitarist Django Reinhardt.  2005: Mature enough to handle several high-traffic sites.  Current: Django is now an open source project with contributors across the world.
  • 5.  Jean "Django" Reinhardt was a Belgian-born French jazz guitarist and composer of Romani background, regarded as one of the greatest musicians of the twentieth century, having written nearly 100 songs,
  • 6. Django – Design Philosophies  Django comes with the following design philosophies:  Loosely Coupled: Django aims to make each element of its stack independent of the others.  Less Coding: Less code so in turn a quick development.  Don't Repeat Yourself (DRY): Everything should be developed only in exactly one place instead of repeating it again and again.  Fast Development: Django's philosophy is to do all it can to facilitate hyper-fast development.  Clean Design: Django strictly maintains a clean design throughout its own code and makes it easy to follow best web-development practices.
  • 7. DJANGO MVC - MVT Pattern  The Model-View-Template (MVT) is slightly different from MVC.  M= Model, The database interface  V= View, Logic for getting stuff in and out of the database  T= Template, The display logic  The template is a HTML file mixed with Django Template Language (DTL).
  • 8. The developer provides the Model, the view and the template then just maps it to a URL and Django does the magic to serve it to the user.
  • 9. Django – Environment  Step 1 – Installing Python  Step 2 - Installing Django  https://www.djangoproject.com/download/  Step 3 – Database Setup  Django supports several major database engines and you can set up any of them based on your comfort.  MySQL  PostgreSQL  SQLite 3  Oracle  MongoDb  GoogleAppEngine Datastore
  • 10.  Step 4 – Web Server  Django comes with a lightweight web serverfor developing and testing applications.  This serveris pre-configured to workwith Django, and more importantly, it restarts wheneveryou modify the code.
  • 11. Django – Creating a Project  In Django, every web app you want to create is called a project; and a project is a sum of applications.  An application is a set of code files relying on the MVT pattern.  As example let's say we want to build a website, the website is our project and, the forum, news, contact engine are applications.  A project is a collection of configuration and apps for a particular website.  A project can contain multiple apps.  An app can be in multiple projects.
  • 12. Create a Project  Whether you are on Windows or Linux, just get a terminal or a cmd prompt and navigate to the place you want yourproject to be created, then use this code:  $ django-admin startproject myproject  This will create a "myproject" folder with the following structure:  myproject/  manage.py  myproject/  __init__.py  settings.py  urls.py  wsgi.py
  • 13. The Project Structure  The “myproject” folder is just your project container, it actually contains two elements:  manage.py: This file is kind of your project local django-admin for interacting with your project via command line (start the development server, sync db...). To get a full list of command accessible via manage.py you can use the code:  $ python manage.py help
  • 14.  The “myproject” subfolder: This folder is the actual python package of your project. It contains four files:  __init__.py: Just for python, treat this folder as package.  settings.py: As the name indicates, your project settings.  urls.py: All links of your project and the function to call.  wsgi.py: If you need to deploy your project over Web ServerGateway Interface (WSGI).
  • 15. Django also supports:  MySQL (django.db.backends.mysql)  PostGreSQL (django.db.backends.postgresql_psycopg2)  Oracle (django.db.backends.oracle) and NoSQL DB  MongoDB(django_mongodb_engine)
  • 16.  Now that your project is created and configured make sure it's working:  $ python manage.py runserver
  • 17. Django – Apps Life Cycle  Create an Application  We assume you are in your project folder. In our main “myproject” folder, the same folder than manage.py:  $ python manage.py startapp myapp
  • 18.  You just created myapp application and like project, Django create a “myapp” folder with the application structure:  myapp/  __init__.py  admin.py  models.py  tests.py  views.py  __init__.py: python handles this folder as a package.  admin.py: This file helps you make the app modifiable in the admin interface.  models.py: This is where all the application models are stored.  tests.py: This is where your unit tests are.  views.py: This is where your application views are.
  • 19. Changing the port & server’s IP  By default, the runserver command starts the development server on the internal IP at port 8000.  If you want to change the server’s port, pass it as a command-line argument. For instance, this command starts the server on port 8080:  $ python manage.py runserver8080  If you want to change the server’s IP, pass it along with the port. So to listen on all public IPs (useful if you want to show off your work on other computers on your network), use:  $ python manage.py runserver0.0.0.0:8000
  • 20. Django - Creating Views  A view function, or “view” for short, is simply a Python function that takes a web request and returns a web response.  This response can be the HTML contents of a Web page, or a redirect, or a 404 error, or an XML document, or an image, etc.  Example: You use view to create web pages, note that you need to associate a view to a URL to see it as a web page.  In Django, views have to be created in the app views.py file.
  • 21. Write yourfirst view Open the file myapp/views.py and put the following Python code in it: myapp/views.py fromdjango.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the myapp index.") •HttpResponse to renderthe HTML •see this view as a page we just need to map it to a URL
  • 22. Call the view  To call the view, we need to map it to a URL - and for this we need a URLconf.  To create a URLconf in the polls directory, create a file called urls.py. myapp/urls.py file include the following code: myapp/urls.py from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index, name='index'), ]
  • 23.  The next step is to point the root URLconf at the myapp.urls module.  In myproject/urls.py, add an import for django.conf.urls.include and insert an include() in the urlpatterns list, so you have: myproject/urls.py from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^myapp/', include(‘myapp.urls')), url(r'^admin/', admin.site.urls), ]
  • 24. Run  Go to http://localhost:8000/myapp/in your browser, and you should see the text  “He llo , wo rld. Yo u’re at the m yapp inde x. ”, which you defined in the index view.  The url() function is passed four arguments, two required: regex and view, and two optional: kwargs, and name.
  • 25.  When to use include()  You should always use include() when you include otherURL patterns.  admin.site.urls is the only exception to this.
  • 26. Templates in Django  A template is just an HTML file, that contains the HTML design of our website.  A Django Template is a sequence of Text that helps in separation of the presentation layer of a document from its data.  A template is simply a text file. It can generate any text- based format (HTML, XML, CSV, etc.).  A Django template is intended to separate the presentation of a document from its data. A template defines placeholders and various bits of basic logic (template tags) that regulate how the document should be displayed. Usually, templates are used for producing HTML.
  • 27. Django – Template System  Django makes it possible to separate python and HTML, the python goes in views and HTML goes in templates. To link the two, Django relies on the render function and the Django Template language.  The RenderFunction  This function takes three parameters:  Request: The initial request.  The path to the template: This is the path relative to the TEMPLATE_DIRS option in the project settings.py variables.  Dictionary of parameters: A dictionary that contains all variables needed in the template. This variable can be created or you can use locals() to pass all local variable declared in the view.
  • 28. Django Template Language (DTL)  Displaying Variables  A variable looks like this: {{variable}}.  The template replaces the variable by the variable sent by the view in the third parameterof the renderfunction.  Let's change our hello.html to display today’s date:
  • 29.  Put .html file here (by default django use this location)  C:Python27Libsite-packagesDjango-1.10.5- py2.7.eggdjangocontribadmintemplates  After in myproject settings.py put this line under TEMPLATES=[] (its show the above path as base_dir)  'DIRS': [os.path.join(BASE_DIR,'templates')],
  • 30. Call the view forhtml Create urls.py undermyapp dirs n put this code. fromdjango.conf.urls import url from. import views urlpatterns = [ url(' ',views.hello), ]
  • 31. Map HTML with yourproject  The next step is to point the root URLconf at the myapp.urls module.  In myproject/urls.py, add an import for django.conf.urls.include and insert an include() in the urlpatterns list, so you have: myproject/urls.py from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^myapp/', include(‘myapp.urls')), url(r'^admin/', admin.site.urls), ]
  • 32. Workwith databsae in Djnago  Database setup  open up myproject/settings.py.  It’s a normal Python module with module-level variables representing Django settings.  By default, the configuration uses SQLite.
  • 33. Creating Models  define your models – essentially, your database layout, with additional metadata.  A model is a class that represents table or collection in ourDB, and where every attribute of the class is a field of the table or collection.  Models are defined in the app/models.py (in ourexample: myapp/models.py)
  • 34. steps  Create models (data structure of our app)  Set the full path of db in myproject/setting.py  Set app name in installed_app  Run manage.py migrate --run-syncdb for default table creation.  Create superuser (admin) using manage.py createsuperuser  Setting admin forregisterourmodel  Checkthe structure in browser
  • 35. Save this in myapp/models.py fromdjango.db import models # Create yourmodels here. class BlogPost(models.Model): title=models.CharField(max_length=150) body=models.TextField() timestamp=models.DateTimeField()
  • 36. Setting admin forregisterour model in myapp/admin.py from django.contrib import admin from myapp import models admin.site.register(models.BlogPost)
  • 37.  Before launching your server, to access your Admin Interface, you need to initiate the database:  python manage.py migrate --run-syncdb  syncdb will create necessary tables orcollections depending on yourdb type, necessary forthe admin interface to run.  Even if you don't have a superuser, you will be prompted to create one.  If you already have a superuser or have forgotten it, you can always create one using the following code:  $ python manage.py createsuperuser
  • 38. Get the Project to Know About Your Application  At this stage we have our "myapp" application, now we need to registerit with ourDjango project "myproject".  To do so, update INSTALLED_APPS tuple in the settings.py file of your project (add your app name):
  • 39.  Now just run the server:  $ python manage.py runserver  And your admin interface is accessible at: http://127.0.0.1:8000/admin/
  • 40. Once connected with yoursuperuser account, you will see the following screen:  That interface will let you administrate Django groups and users, and all registered models in your app.  The interface gives you the ability to do at least the "CRUD" (Create, Read, Update, Delete) operations on yourmodels.
  • 41. Pros of Django  Object-Relational Mapping (ORM) Support: Django provides a bridge between the data model and the database engine, and supports a large set of database systems including MySQL, Oracle, Postgres, etc.  Multilingual Support: Django supports multilingual websites through its built-in internationalization system. So you can develop your website, which would support multiple languages.
  • 42.  FrameworkSupport: Django has built-in support for Ajax, RSS, Caching and various other frameworks.  Administration GUI: Django provides a nice ready-to-use user interface for administrative activities.  Development Environment: Django comes with a lightweight web server to facilitate end-to-end application development and testing.
  • 43. Cons of Django  Not the best for small projects  Heavy because we have to use the whole django  Less code but we have to manage lot of stuff.  Configuration is more  Required MVT
  • 44. Who uses Django  Pinterest  Event brite  Prezi  Bitbucket  Nasa offcial website  Spotify  Instagram