SlideShare uma empresa Scribd logo
1 de 15
Introduction to Django
Presented by: Ahmed Salama
Software Engineer at Ibtikar Technologies
A web development framework for Python
● What is Django?
● History
● MVC and MVT design patterns
● Django Architecture
TOC
● Django Modules
● Install Django
● Steps to create Django project
● Let’s make a small ToDo App
What does “Django” means?
● Django is named after Django Reinhardt, a jazz manouche guitarist from
the 1930s to early 1950s. To this day, he’s considered one of the best
guitarists of all time.
● Django is pronounced JANG-oh. Rhymes with FANG-oh. The “D” is silent.
Django is a free open source Web frameworks written in python
1
2
3
History
● Created in 2003, When the Web programmers at Lawrence Journal-World
newspaper, Adrian Holovaty and Simon Willison, began using Python to build
applications.
● It was released publicly in 2008, Official site: https://www.djangoproject.com/
● Django’s now run by an international team of volunteers.
● Which sites use Django?? DjangoSites.org contains list of django websites and you
can register yours.
● Well-known sites: Disqus - BitBucket - Instagram - Mozilla Firefox(help page, Add-
ons ) - Pinterest( 33 million visit per month) - NASA - Onion(satirical articles) - The
washington post - eventbrite
Model-View-Controller(MVC) Design pattern
● Model: A representation of your data. It’s not the actual data, but an interface to the data. It allows you to pull data
from your database without knowing the intricacies of the underlying database(ORM).
● View: What you see in the browser. It’s the presentation layer for your model.
● Controller: controls the flow of information between the model and the view. It uses programmed logic to decide
what information is pulled from the database via the model and what information is passed to the view.
Model-View-Template(MTV) Design pattern
● Model: Data access layer.
● Template: The presentation layer. (Takes the role of ‘View’ on MVC)
● View: the business logic layer. Controls what a user sees. This layer contains the logic that accesses the model and
defers to the appropriate template(s). You can think of it as the bridge between models and templates.
● The controller role is handled by the Framework itself and this is the most advantage of Django’s MVC.
Django Modules
★ Administration interface (CRUD interface)
★ Authentication system
★ Comments system
★ Forms handling
★ Sessions
★ Syndication framework (RSS and Atom Feeds)
★ Caching
★ Internationalization
★ Localization
★ Custom Middleware
Why Django for Web development?
● Provides auto generated web admin to ease the website administration.
● Provides you template system to define HTML template for your web pages to
avoid code duplication.
● Allows you to define what URL be for a given Function.
● Everything is in python.
● Django is not only one of many web frameworks available. It is one of the
leading frameworks for developing scalable, secure and maintainable web
applications.
Install Django
● Install python > $ sudo apt-get install python3
● Install pip > $ sudo apt-get install python3-pip
● Install virtualenv > $ pip3 install virtualenv
● Install Django > $ pip install django
Follow thes steps: https://www.digitalocean.com/community/tutorials/how-to-install-django-and-set-up-a-development-
environment-on-ubuntu-16-04
Steps to create Django project
➢ Start a project $ django-admin startproject <project_name>
➢ Start an application $ python manage.py startapp <app_name>
➢ Define your models # models.py
➢ Write your templates templates/
➢ Define your views # views.py
➢ Create URL mapping # urls.py
➢ Test Application # test.py
➢ Edit the Django’s default database(SQLite) to MySQL or Postgresql -if you want.
➢ Define DB Settings in Settings.py
➢ Deploy Application -make it public(Heroku, etc.)
Django’s generated code (Starter code)
> MyProject/
> MyProject/
> __init__.py -> Call wsgi.py
> settings.py -> Configuration file
> urls.py -> URL Mapping for the project
> wsgi.py -> The start point of the project
> MyApp/
> __init__.py
> migrations/ -> History(Versions) of database changes
> admin.py -> Register your models here(add them to admin website)
> apps.py
> tests.py
> models.py
> views.py
> manage.py -> Interact with django( runserver, migrate(commit changes to database)
..)
Add to the starter code..
● Import application’s view.py in urls.py. < from myApp import views as app1_views>
Append functions to urls < path('home/', app1_views.index, name='index'), >
● Add your application to intalled_apps array which in settings.py > to add it to admin site.
● Templates/ directory contains the html files of each application. < os.path.join(BASE_DIR, ‘templates’) >
● Staticfiles/ directory to add css, js, img files to it. <STATICFILES_DIRS = [ os.path.join(BASE_DIR, "staticfiles"), ] >
● Create the Admin website > $python3 manage.py migrate
● Create super user( system admin) > $ python3 manage.py createsuperuser
● Design Error pages (400, 403, 404, 500) -Django take care of it in local development.
● Adjust the settings file for production(deployment)
Run Django’s server with $ python3 manage.py runserver
Let’s make a small project!
ToDo Application
1- TaskModel has: Name, Description, Owner(foreignKey), Responsibles(Many2one), is_done.
2- Color it with ‘staticfiles’.
3- add/remove tasks from admin site.
Further reading & Resources
● Django Documentations: https://docs.djangoproject.com/en/2.1/
● Udemy course: https://www.udemy.com/python-ecommerce-build-a-django-ecommerce-web-application/
● The Django Book: https://djangobook.com/
● Django Girls: https://djangogirls.org/ ( We inspire women to fall in love with programming.)
Thanks!

Mais conteúdo relacionado

Mais procurados

A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
Ganga Ram
 

Mais procurados (20)

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Express js
Express jsExpress js
Express js
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...Python Django tutorial | Getting Started With Django | Web Development With D...
Python Django tutorial | Getting Started With Django | Web Development With D...
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC Framework
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Django Girls Tutorial
Django Girls TutorialDjango Girls Tutorial
Django Girls Tutorial
 
Django PPT.pptx
Django PPT.pptxDjango PPT.pptx
Django PPT.pptx
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
Mongo db
Mongo dbMongo db
Mongo db
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
AngularJS
AngularJS AngularJS
AngularJS
 
Web engineering - MVC
Web engineering - MVCWeb engineering - MVC
Web engineering - MVC
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 

Semelhante a Introduction to Django

Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
Ilian Iliev
 

Semelhante a Introduction to Django (20)

Django by rj
Django by rjDjango by rj
Django by rj
 
Django
DjangoDjango
Django
 
Free django
Free djangoFree django
Free django
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and Architecture
 
Django framework
Django frameworkDjango framework
Django framework
 
Why Django for Web Development
Why Django for Web DevelopmentWhy Django for Web Development
Why Django for Web Development
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| Edureka
 
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)
 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
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...
 
Introduction To Django
Introduction To DjangoIntroduction To Django
Introduction To Django
 
Akash rajguru project report sem v
Akash rajguru project report sem vAkash rajguru project report sem v
Akash rajguru project report sem v
 
React django
React djangoReact django
React django
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
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
 
Django framework
Django framework Django framework
Django framework
 
django
djangodjango
django
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
 

Mais de Ahmed Salama (9)

Seven Ways To Be a Healthy Programmer!.pdf
Seven Ways To Be a Healthy Programmer!.pdfSeven Ways To Be a Healthy Programmer!.pdf
Seven Ways To Be a Healthy Programmer!.pdf
 
10 Code Anti-Patterns to Avoid in Software Development.pdf
10 Code Anti-Patterns to Avoid in Software Development.pdf10 Code Anti-Patterns to Avoid in Software Development.pdf
10 Code Anti-Patterns to Avoid in Software Development.pdf
 
Introduction to web development
Introduction to web developmentIntroduction to web development
Introduction to web development
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Quick Start to marketing.
Quick Start to marketing.Quick Start to marketing.
Quick Start to marketing.
 
Distributed database
Distributed databaseDistributed database
Distributed database
 
Konard zuse
Konard zuseKonard zuse
Konard zuse
 
DDOS Attack
DDOS Attack DDOS Attack
DDOS Attack
 
Introduction to Computer Science Department
Introduction to Computer Science DepartmentIntroduction to Computer Science Department
Introduction to Computer Science Department
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Introduction to Django

  • 1. Introduction to Django Presented by: Ahmed Salama Software Engineer at Ibtikar Technologies A web development framework for Python
  • 2. ● What is Django? ● History ● MVC and MVT design patterns ● Django Architecture TOC ● Django Modules ● Install Django ● Steps to create Django project ● Let’s make a small ToDo App
  • 3. What does “Django” means? ● Django is named after Django Reinhardt, a jazz manouche guitarist from the 1930s to early 1950s. To this day, he’s considered one of the best guitarists of all time. ● Django is pronounced JANG-oh. Rhymes with FANG-oh. The “D” is silent. Django is a free open source Web frameworks written in python 1 2 3
  • 4. History ● Created in 2003, When the Web programmers at Lawrence Journal-World newspaper, Adrian Holovaty and Simon Willison, began using Python to build applications. ● It was released publicly in 2008, Official site: https://www.djangoproject.com/ ● Django’s now run by an international team of volunteers. ● Which sites use Django?? DjangoSites.org contains list of django websites and you can register yours. ● Well-known sites: Disqus - BitBucket - Instagram - Mozilla Firefox(help page, Add- ons ) - Pinterest( 33 million visit per month) - NASA - Onion(satirical articles) - The washington post - eventbrite
  • 5. Model-View-Controller(MVC) Design pattern ● Model: A representation of your data. It’s not the actual data, but an interface to the data. It allows you to pull data from your database without knowing the intricacies of the underlying database(ORM). ● View: What you see in the browser. It’s the presentation layer for your model. ● Controller: controls the flow of information between the model and the view. It uses programmed logic to decide what information is pulled from the database via the model and what information is passed to the view.
  • 6. Model-View-Template(MTV) Design pattern ● Model: Data access layer. ● Template: The presentation layer. (Takes the role of ‘View’ on MVC) ● View: the business logic layer. Controls what a user sees. This layer contains the logic that accesses the model and defers to the appropriate template(s). You can think of it as the bridge between models and templates. ● The controller role is handled by the Framework itself and this is the most advantage of Django’s MVC.
  • 7. Django Modules ★ Administration interface (CRUD interface) ★ Authentication system ★ Comments system ★ Forms handling ★ Sessions ★ Syndication framework (RSS and Atom Feeds) ★ Caching ★ Internationalization ★ Localization ★ Custom Middleware
  • 8. Why Django for Web development? ● Provides auto generated web admin to ease the website administration. ● Provides you template system to define HTML template for your web pages to avoid code duplication. ● Allows you to define what URL be for a given Function. ● Everything is in python. ● Django is not only one of many web frameworks available. It is one of the leading frameworks for developing scalable, secure and maintainable web applications.
  • 9. Install Django ● Install python > $ sudo apt-get install python3 ● Install pip > $ sudo apt-get install python3-pip ● Install virtualenv > $ pip3 install virtualenv ● Install Django > $ pip install django Follow thes steps: https://www.digitalocean.com/community/tutorials/how-to-install-django-and-set-up-a-development- environment-on-ubuntu-16-04
  • 10. Steps to create Django project ➢ Start a project $ django-admin startproject <project_name> ➢ Start an application $ python manage.py startapp <app_name> ➢ Define your models # models.py ➢ Write your templates templates/ ➢ Define your views # views.py ➢ Create URL mapping # urls.py ➢ Test Application # test.py ➢ Edit the Django’s default database(SQLite) to MySQL or Postgresql -if you want. ➢ Define DB Settings in Settings.py ➢ Deploy Application -make it public(Heroku, etc.)
  • 11. Django’s generated code (Starter code) > MyProject/ > MyProject/ > __init__.py -> Call wsgi.py > settings.py -> Configuration file > urls.py -> URL Mapping for the project > wsgi.py -> The start point of the project > MyApp/ > __init__.py > migrations/ -> History(Versions) of database changes > admin.py -> Register your models here(add them to admin website) > apps.py > tests.py > models.py > views.py > manage.py -> Interact with django( runserver, migrate(commit changes to database) ..)
  • 12. Add to the starter code.. ● Import application’s view.py in urls.py. < from myApp import views as app1_views> Append functions to urls < path('home/', app1_views.index, name='index'), > ● Add your application to intalled_apps array which in settings.py > to add it to admin site. ● Templates/ directory contains the html files of each application. < os.path.join(BASE_DIR, ‘templates’) > ● Staticfiles/ directory to add css, js, img files to it. <STATICFILES_DIRS = [ os.path.join(BASE_DIR, "staticfiles"), ] > ● Create the Admin website > $python3 manage.py migrate ● Create super user( system admin) > $ python3 manage.py createsuperuser ● Design Error pages (400, 403, 404, 500) -Django take care of it in local development. ● Adjust the settings file for production(deployment) Run Django’s server with $ python3 manage.py runserver
  • 13. Let’s make a small project! ToDo Application 1- TaskModel has: Name, Description, Owner(foreignKey), Responsibles(Many2one), is_done. 2- Color it with ‘staticfiles’. 3- add/remove tasks from admin site.
  • 14. Further reading & Resources ● Django Documentations: https://docs.djangoproject.com/en/2.1/ ● Udemy course: https://www.udemy.com/python-ecommerce-build-a-django-ecommerce-web-application/ ● The Django Book: https://djangobook.com/ ● Django Girls: https://djangogirls.org/ ( We inspire women to fall in love with programming.)

Notas do Editor

  1. 400> Bad request 403> Permission denied 404> page not found 500> server down
  2. Owner = models.foreignKey(‘auth.user’, on_delete=models.CASCADE) Responsibles = models.