SlideShare a Scribd company logo
1 of 44
Download to read offline
Django
Beyond Basics
Who is this for?
NOOB GOOD CHUCKNORRIS
What I thought…

NOOB GOOD CHUCKNORRIS
It is more like…
DESIGNER
BIG PICTUREGUY OPERATIONS
ADMIN
RAILS GUY
@arocks
arunrocks.com
Hi!
Disclaimer
This presentationdoesnot aim tobe a
comprehensiveoverviewof any part of Django.
Thereare severaltutorialscoveringvarious
aspectsof theframework. Insteadthisis talkis
part experiencesharing,part advocacyand
part entertainment.
What is Django?
It is just a framework!
Definitely not a CMS!
Get the BIG picture
The BIG picture slide
Thanks to Karen Rustad& Asheesh Laroia
Also starring…
• Lightweight,standaloneweb serverfor dev
• Formserializationand validationsystem
• Flexiblecachingframework
• Supportfor middlewareclasses atvariouslevels
• Internationalizationsystem
• Unit testframework
Why is Django Awesome?
List of awesome-ness
• Admin
• Security
• Greatdocumentation
• Friendlycommunity
• Stable
• Batteriesincluded
• OpenSource!
Comingfrom PHP/ASP
background
Coming from PHP/ASPbackground
Step 1: ForgetEverything,esphow easylife was…
Step 2:Thinkarchitecturefirst
Step3:ThinkaboutSeparationof Concerns
Step 4:???
Step 5: Profit!!!
101bad excuses not touse Django
But Django is too heavy!
Flask
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
Djangoexampleis onefile& almostthesame size!
Django
from django.http import HttpResponse
from django.conf.urls.defaults import patterns
DEBUG=True
ROOT_URLCONF = 'pico'
DATABASES = { 'default': {} }
SECRET_KEY = '0123456789‘ * 50
def index(request):
return HttpResponse('Hello World!')
urlpatterns = patterns('', (r'^$', index))
$ PYTHONPATH=. django-admin.py runserver
0.0.0.0:8000 --settings=pico
No,
It is batteries included!
(+ cool downloadable apps)
But Django is too ugly!
Why use:
“example.com/product/[0-9]+”
?
Isn’t this is much cooler:
“example.com/product/{id}”
? 
SQL Injection!
example.com/product/1 or 1=1
will become:
SELECT * FROM Products WHERE ID = 1 OR 1=1
EvenDjango will not always save you:
“example.com/product/(.+)”
Avoid!
Be as strict as possible:
“example.com/product/[0-9]+”
Looksprettier now, huh?
Why not Django?
• Unusually highperformanceneeds
• ExistingDatabase models?
• Migrations?
• ORM/Templateisnot enough
Inotherwords,youwantto replaceall of Django’s
components.Whichyou would eventually?!
Best Practices
• Distrust outsidedata. Sanitizeeverything!
• Don’tleakimplementationdetails.
• FatterModels/Managersand LeanerViews
• FollowPEP8and readable names
• Be asDRY as possible.
• Breakdown intoreusable Apps
novice questions
What is a QuerySet?
Why is media separate?
Which IDE?
How to deploy?
Must-learn Python Packages
Must-learn Python Packages
• Pip – Don’tstart withoutthis!
• iPython/BPython– Betterthanvanillaconsole
• Pudb– Bestdebugger
• Fabric– Easydeployment
But what goes well with Django?
Must-learn Django Packages
Must-learn Django Packages
• Django-debug-toolbar– Only inDEV!
• Django_compressor– Notjust compression
• Django-extensions– Tonsof goodies
• South– Gettingintegrated?
• Celery– DelayedGratification
• Tastypie*–Build yummy APIs
* Or anything that suits you
Other cool Django Packages
• Djangosocialauth:One app to most Social logins
• DjangoPaypal:PayPal Payments Standard & Pro
• crispy-forms:NiceHTML for forms
• django-taggit:Implement tags easily
• Psycopg2: Talk to PostgreSQL, a solid database
• django-storages:Store anywhere - Cloud, DB or FTP
My Django Workflow
1) Create a new Django project
2) Find a3rd party app or create anapp
3) Write/Improve models.py
4) Play with queries onconsole. Run syncdb.
5) Add abare admin.py
6) Add data from admin UI
7) Write views.py. Leverage CBVs
8) If needed, adda model form to forms.py
9) Add views to urls.py
10) Jump to step 3till app looks good
11) jump to step 2
For examples, head to arunrocks.com
A simplistic Django workflow…
1) Create a new Django project
2) Find a3rd party app or create an app
3) Write/Improve models.py
4) Play with queries onconsole. Repeat step 3
5) Add abare admin.py
6) Add data from admin UI
7) Write views.py. Leverage CBVs
8) If needed, adda model form to forms.py
9) Add views to urls.py
10) Jump to step 3till app looks good
Make friends with Git, South, Fabric…
A better Django workflow…
$ ./manage.py schemamigration app --initial
$ ./manage.py migrate app
$ ./manage.py schemamigration app --auto
$ git init
Write tests.py
Fabric/Puppet/Chef
Forms are easy!
Forms are easy!
• Use formsas much as possible(Hint:security)
• ModelFormscovermost uses case
• Butselect whichfields showin ModelForms
• Hard set all defaults beforeform.save
• FormViewis a greatgenericviewfor forms
• Usingbootstrap?Use crispy-formsto savetime
Should I use CBVs?
Ok, I made a Django
site. Now what?
Ok, I made a Django site. Now what?
• Turn off DEBUG
• Use HTTPS logins
• Set X-Frame-
Optionsheader
• Use SESSION_COOKIE_
SECURE
• Change /admin/ url Oreasier,go to
http://ponycheckup.com/
@arocks

More Related Content

What's hot

AzovDevMeetup 2016 | Angular 2: обзор | Александр Шевнин
AzovDevMeetup 2016 | Angular 2: обзор | Александр ШевнинAzovDevMeetup 2016 | Angular 2: обзор | Александр Шевнин
AzovDevMeetup 2016 | Angular 2: обзор | Александр ШевнинJSC “Arcadia Inc”
 
Android application architecture
Android application architectureAndroid application architecture
Android application architectureRomain Rochegude
 
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in DjangoDjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in DjangoCasey Kinsey
 
Test Automation Framework using Cucumber BDD Overview - part 2
Test Automation Framework using Cucumber BDD Overview - part 2Test Automation Framework using Cucumber BDD Overview - part 2
Test Automation Framework using Cucumber BDD Overview - part 2Mindfire Solutions
 
Creating Gradle Plugins
Creating Gradle PluginsCreating Gradle Plugins
Creating Gradle PluginsAnnyce Davis
 
Develop Maintainable Apps
Develop Maintainable AppsDevelop Maintainable Apps
Develop Maintainable AppsAnnyce Davis
 
[Srijan Wednesday Webinars] Choosing the Right Testing Framework
[Srijan Wednesday Webinars] Choosing the Right Testing Framework[Srijan Wednesday Webinars] Choosing the Right Testing Framework
[Srijan Wednesday Webinars] Choosing the Right Testing FrameworkSrijan Technologies
 
[Android] DI in multimodule application
[Android] DI in multimodule application[Android] DI in multimodule application
[Android] DI in multimodule applicationOleg Mazhukin
 
Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Mindfire Solutions
 
Testing nightwatch, by David Torroija
Testing nightwatch, by David TorroijaTesting nightwatch, by David Torroija
Testing nightwatch, by David TorroijaDavid Torroija
 
Protractor end-to-end testing framework for angular js
Protractor   end-to-end testing framework for angular jsProtractor   end-to-end testing framework for angular js
Protractor end-to-end testing framework for angular jscodeandyou forums
 
Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Unit testing @ WordPress Meetup Tilburg 7 januari 2014Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Unit testing @ WordPress Meetup Tilburg 7 januari 2014Barry Kooij
 
TestingAR XX - Protractor e2e Test Framework - Introduction what we have lear...
TestingAR XX - Protractor e2e Test Framework - Introduction what we have lear...TestingAR XX - Protractor e2e Test Framework - Introduction what we have lear...
TestingAR XX - Protractor e2e Test Framework - Introduction what we have lear...TestingAR Meetup
 

What's hot (20)

Dagger2 Intro
Dagger2 IntroDagger2 Intro
Dagger2 Intro
 
AzovDevMeetup 2016 | Angular 2: обзор | Александр Шевнин
AzovDevMeetup 2016 | Angular 2: обзор | Александр ШевнинAzovDevMeetup 2016 | Angular 2: обзор | Александр Шевнин
AzovDevMeetup 2016 | Angular 2: обзор | Александр Шевнин
 
Android application architecture
Android application architectureAndroid application architecture
Android application architecture
 
Workshop - E2e tests with protractor
Workshop - E2e tests with protractorWorkshop - E2e tests with protractor
Workshop - E2e tests with protractor
 
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in DjangoDjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
 
Test Automation Framework using Cucumber BDD Overview - part 2
Test Automation Framework using Cucumber BDD Overview - part 2Test Automation Framework using Cucumber BDD Overview - part 2
Test Automation Framework using Cucumber BDD Overview - part 2
 
Automated UI Testing
Automated UI TestingAutomated UI Testing
Automated UI Testing
 
Dagger 2
Dagger 2Dagger 2
Dagger 2
 
Creating Gradle Plugins
Creating Gradle PluginsCreating Gradle Plugins
Creating Gradle Plugins
 
Develop Maintainable Apps
Develop Maintainable AppsDevelop Maintainable Apps
Develop Maintainable Apps
 
[Srijan Wednesday Webinars] Choosing the Right Testing Framework
[Srijan Wednesday Webinars] Choosing the Right Testing Framework[Srijan Wednesday Webinars] Choosing the Right Testing Framework
[Srijan Wednesday Webinars] Choosing the Right Testing Framework
 
[Android] DI in multimodule application
[Android] DI in multimodule application[Android] DI in multimodule application
[Android] DI in multimodule application
 
Marcin Wasilczyk - Page objects with selenium
Marcin Wasilczyk - Page objects with seleniumMarcin Wasilczyk - Page objects with selenium
Marcin Wasilczyk - Page objects with selenium
 
Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)Test Automation Framework using Cucumber BDD overview (part 1)
Test Automation Framework using Cucumber BDD overview (part 1)
 
Testing nightwatch, by David Torroija
Testing nightwatch, by David TorroijaTesting nightwatch, by David Torroija
Testing nightwatch, by David Torroija
 
Protractor
Protractor Protractor
Protractor
 
Protractor end-to-end testing framework for angular js
Protractor   end-to-end testing framework for angular jsProtractor   end-to-end testing framework for angular js
Protractor end-to-end testing framework for angular js
 
Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Unit testing @ WordPress Meetup Tilburg 7 januari 2014Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Unit testing @ WordPress Meetup Tilburg 7 januari 2014
 
TestingAR XX - Protractor e2e Test Framework - Introduction what we have lear...
TestingAR XX - Protractor e2e Test Framework - Introduction what we have lear...TestingAR XX - Protractor e2e Test Framework - Introduction what we have lear...
TestingAR XX - Protractor e2e Test Framework - Introduction what we have lear...
 
Cypress workshop for JSFoo 2019
Cypress  workshop for JSFoo 2019Cypress  workshop for JSFoo 2019
Cypress workshop for JSFoo 2019
 

Similar to Django Beyond Basics Guide

Move out from AppEngine, and Python PaaS alternatives
Move out from AppEngine, and Python PaaS alternativesMove out from AppEngine, and Python PaaS alternatives
Move out from AppEngine, and Python PaaS alternativestzang ms
 
Django getting start
Django getting startDjango getting start
Django getting startshengwu83
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in DjangoLakshman Prasad
 
How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015hirokiky
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersRosario Renga
 
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Waysmalltown
 
Netflix oss season 2 episode 1 - meetup Lightning talks
Netflix oss   season 2 episode 1 - meetup Lightning talksNetflix oss   season 2 episode 1 - meetup Lightning talks
Netflix oss season 2 episode 1 - meetup Lightning talksRuslan Meshenberg
 
10 things you should know about django
10 things you should know about django10 things you should know about django
10 things you should know about djangoAdieu
 
Django Article V0
Django Article V0Django Article V0
Django Article V0Udi Bauman
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGuillaume Laforge
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?Dmitri Shiryaev
 
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
 
Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django ArchitectureRami Sayar
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-wayRobert Lujo
 

Similar to Django Beyond Basics Guide (20)

Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Django Girls Tutorial
Django Girls TutorialDjango Girls Tutorial
Django Girls Tutorial
 
Django
DjangoDjango
Django
 
Move out from AppEngine, and Python PaaS alternatives
Move out from AppEngine, and Python PaaS alternativesMove out from AppEngine, and Python PaaS alternatives
Move out from AppEngine, and Python PaaS alternatives
 
Django getting start
Django getting startDjango getting start
Django getting start
 
django
djangodjango
django
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in Django
 
How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
 
Netflix oss season 2 episode 1 - meetup Lightning talks
Netflix oss   season 2 episode 1 - meetup Lightning talksNetflix oss   season 2 episode 1 - meetup Lightning talks
Netflix oss season 2 episode 1 - meetup Lightning talks
 
10 things you should know about django
10 things you should know about django10 things you should know about django
10 things you should know about django
 
Django Article V0
Django Article V0Django Article V0
Django Article V0
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Django Introdcution
Django IntrodcutionDjango Introdcution
Django Introdcution
 
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?Hadoop:  Big Data Stacks validation w/ iTest  How to tame the elephant?
Hadoop: Big Data Stacks validation w/ iTest How to tame the elephant?
 
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...
 
Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django Architecture
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
 

Recently uploaded

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Recently uploaded (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Django Beyond Basics Guide

  • 2. Who is this for?
  • 3. NOOB GOOD CHUCKNORRIS What I thought… 
  • 4. NOOB GOOD CHUCKNORRIS It is more like… DESIGNER BIG PICTUREGUY OPERATIONS ADMIN RAILS GUY
  • 6. Disclaimer This presentationdoesnot aim tobe a comprehensiveoverviewof any part of Django. Thereare severaltutorialscoveringvarious aspectsof theframework. Insteadthisis talkis part experiencesharing,part advocacyand part entertainment.
  • 8. It is just a framework!
  • 10. Get the BIG picture
  • 11. The BIG picture slide Thanks to Karen Rustad& Asheesh Laroia
  • 12. Also starring… • Lightweight,standaloneweb serverfor dev • Formserializationand validationsystem • Flexiblecachingframework • Supportfor middlewareclasses atvariouslevels • Internationalizationsystem • Unit testframework
  • 13. Why is Django Awesome?
  • 14. List of awesome-ness • Admin • Security • Greatdocumentation • Friendlycommunity • Stable • Batteriesincluded • OpenSource!
  • 16. Coming from PHP/ASPbackground Step 1: ForgetEverything,esphow easylife was… Step 2:Thinkarchitecturefirst Step3:ThinkaboutSeparationof Concerns Step 4:??? Step 5: Profit!!!
  • 17. 101bad excuses not touse Django
  • 18. But Django is too heavy!
  • 19. Flask from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run() Djangoexampleis onefile& almostthesame size! Django from django.http import HttpResponse from django.conf.urls.defaults import patterns DEBUG=True ROOT_URLCONF = 'pico' DATABASES = { 'default': {} } SECRET_KEY = '0123456789‘ * 50 def index(request): return HttpResponse('Hello World!') urlpatterns = patterns('', (r'^$', index)) $ PYTHONPATH=. django-admin.py runserver 0.0.0.0:8000 --settings=pico
  • 20. No, It is batteries included! (+ cool downloadable apps)
  • 21. But Django is too ugly!
  • 22. Why use: “example.com/product/[0-9]+” ? Isn’t this is much cooler: “example.com/product/{id}” ?  SQL Injection!
  • 23. example.com/product/1 or 1=1 will become: SELECT * FROM Products WHERE ID = 1 OR 1=1
  • 24. EvenDjango will not always save you: “example.com/product/(.+)” Avoid!
  • 25. Be as strict as possible: “example.com/product/[0-9]+”
  • 27. Why not Django? • Unusually highperformanceneeds • ExistingDatabase models? • Migrations? • ORM/Templateisnot enough Inotherwords,youwantto replaceall of Django’s components.Whichyou would eventually?!
  • 28. Best Practices • Distrust outsidedata. Sanitizeeverything! • Don’tleakimplementationdetails. • FatterModels/Managersand LeanerViews • FollowPEP8and readable names • Be asDRY as possible. • Breakdown intoreusable Apps
  • 29. novice questions What is a QuerySet? Why is media separate? Which IDE? How to deploy?
  • 31. Must-learn Python Packages • Pip – Don’tstart withoutthis! • iPython/BPython– Betterthanvanillaconsole • Pudb– Bestdebugger • Fabric– Easydeployment
  • 32. But what goes well with Django?
  • 34. Must-learn Django Packages • Django-debug-toolbar– Only inDEV! • Django_compressor– Notjust compression • Django-extensions– Tonsof goodies • South– Gettingintegrated? • Celery– DelayedGratification • Tastypie*–Build yummy APIs * Or anything that suits you
  • 35. Other cool Django Packages • Djangosocialauth:One app to most Social logins • DjangoPaypal:PayPal Payments Standard & Pro • crispy-forms:NiceHTML for forms • django-taggit:Implement tags easily • Psycopg2: Talk to PostgreSQL, a solid database • django-storages:Store anywhere - Cloud, DB or FTP
  • 37. 1) Create a new Django project 2) Find a3rd party app or create anapp 3) Write/Improve models.py 4) Play with queries onconsole. Run syncdb. 5) Add abare admin.py 6) Add data from admin UI 7) Write views.py. Leverage CBVs 8) If needed, adda model form to forms.py 9) Add views to urls.py 10) Jump to step 3till app looks good 11) jump to step 2 For examples, head to arunrocks.com A simplistic Django workflow…
  • 38. 1) Create a new Django project 2) Find a3rd party app or create an app 3) Write/Improve models.py 4) Play with queries onconsole. Repeat step 3 5) Add abare admin.py 6) Add data from admin UI 7) Write views.py. Leverage CBVs 8) If needed, adda model form to forms.py 9) Add views to urls.py 10) Jump to step 3till app looks good Make friends with Git, South, Fabric… A better Django workflow… $ ./manage.py schemamigration app --initial $ ./manage.py migrate app $ ./manage.py schemamigration app --auto $ git init Write tests.py Fabric/Puppet/Chef
  • 40. Forms are easy! • Use formsas much as possible(Hint:security) • ModelFormscovermost uses case • Butselect whichfields showin ModelForms • Hard set all defaults beforeform.save • FormViewis a greatgenericviewfor forms • Usingbootstrap?Use crispy-formsto savetime
  • 41. Should I use CBVs?
  • 42. Ok, I made a Django site. Now what?
  • 43. Ok, I made a Django site. Now what? • Turn off DEBUG • Use HTTPS logins • Set X-Frame- Optionsheader • Use SESSION_COOKIE_ SECURE • Change /admin/ url Oreasier,go to http://ponycheckup.com/