SlideShare a Scribd company logo
1 of 26
Download to read offline
12 tips on Django Best Practices
David Arcos
catchoom.com | @catchoom
12 tips on Django Best Practices
Some (personal) suggestions on:
- Development
- Deployment
- External tools

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Hi! I'm David Arcos
- Python/Django developer
- discovered Django in 2007 (v0.96)
- professionally since 2008

- Web backend, distributed systems,
databases, scalability, security
- Team leader at Catchoom

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices

- Image Recognition SaaS
- Top recognition results, shortest response times
- Easy to integrate into your apps/services

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Why Python? PEP 20, The Zen of Python:
- “Beautiful is better than ugly”
- “Simple is better than complex”
- “Complex is better than complicated”
- “Readability counts”
- “Special cases aren't special enough to break the rules”
- “If the implementation is hard to explain, it's a bad idea”
- (…)
http://www.python.org/dev/peps/pep-0020/

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Why Django?
- "The Web framework for perfectionists with deadlines"
- Django design philosophy:

- loose coupling, less code, DRY, consistency, etc...
- https://docs.djangoproject.com/en/dev/misc/design-philosophies/

- technically: tons of django apps, very good doc

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Virtualenv:
- “one project, one virtualenv”
- projects with different dependencies, package versions
- easier to deploy. Forget dependency hell!
- virtualenvwrapper is a convenient tool

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Dependencies:
- use pip:
pip install catchoom
- save the dependencies in a requirements.txt file:
pip freeze > requirements.txt
pip install -r requirements.txt
David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Layout: projects and apps
- project = the full website. app = python library
repository/
|-- doc
`-- project
|-- apps
|
|-- app1
|
|-- app2
|
`-- app3
`-- settings
David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices

- use short, obvious, single-word names for your apps
- many small apps is better than a few giant apps:
- explain an app in a sentence. If you can't, split the app
- rather than expand an app, write a new app
- don't reinvent the wheel!
- django.contrib
- 3rd-party apps
David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Settings:
- multiple settings files:
- per environment: dev, testing, staging, production
- per developer (local settings, use the hostname)
- all settings files must inherit from base, so you can do:
INSTALLED_APPS += ('debug_toolbar', )

- version control all the settings!
David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Django is a MTV framework
- Model (app/models.py)
- Template (app/templates/*.html)
- View (app/views.py)

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Fat models, thin views...
- logic should go to the models (and forms, signals...)
- keep the views at a minimum
Good example: django.contrib.auth.models.User

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices

- why? Because of maintainability!
- a model is much easier to test
- reusable logic: form validation, signals, etc
- the code becomes clearer, more self-documenting

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
...and stupid templates!
- your template layer should be as thin as possible
- (by design) django templates are limited, constrained
- doesn't fit your use case? Use jinja2 in those views
- Hey, but I get ugly generated HTML!
- doesn't matter, you want maintainable templates

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Deployment:
- web server:
- Nginx + gunicorn
- Supervisord to keep it alive.
- static server:
- Nginx. Or any CDN.
David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Fabric:
"a library and command-line tool for streamlining the use of SSH for
application deployment or systems administration tasks"

- to automate deployments, migrations, execute
management commands, monitoring...
- no more repetitive maintainance tasks done manually!

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
South:
"intelligent schema and data migrations for Django projects"

- creates migration files automatically.
- You can still do changes
- can do backward migrations
- will avoid disasters. Use it!
David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Celery:
"asynchronous task queue/job queue based on distributed message passing"

- execute tasks asynchronously, in a pool workers
- cpu-intensive or I/O-intensive tasks:
- emails, pdfs, thumbnails, crawling, requests...
- Celery needs a Message Queue
- Instead of RabbitMQ, try Redis.
David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Redis:
"An advanced key-value store. It is often referred to as a data structure
server since keys can contain strings, hashes, lists, sets and sorted sets."

- store ephemeral data (active sessions)
- general cache (memcached compatible)
- real-time calculations: stats, monitoring, throttling...
- messages: channels (pub-sub), lists (push/blpop)
- indexes/filters (“sort by hits”)
David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Sentry:
"realtime event logging and aggregation platform"
- monitor errors, get all the info to do a post-mortem
- uses the Python logger, easy to configure
- deploy a Sentry instance
- or use getsentry.com
David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Debugging:
- ipython (already in ./manage.py shell)
- ipdb

import ipdb
ipdb.set_trace()

- django-debug-toolbar
- very powerful
- use it to optimize db performance, view by view
David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices
Summary:
- follow the Django philosophy (when possible)
- stand on the shoulder of giants: use existing apps

David Arcos | @DZPM

Catchoom | http://catchoom.com
12 tips on Django Best Practices

Thanks for attending!
- http://slideshare.net/DZPM
- Questions?

David Arcos | @DZPM

Catchoom | http://catchoom.com
Questions?

catchoom.com | @catchoom
12 tips on Django Best Practices

Thanks for attending!
- http://slideshare.net/DZPM

David Arcos | @DZPM

Catchoom | http://catchoom.com

More Related Content

What's hot

Django로 쇼핑몰 만들자
Django로 쇼핑몰 만들자Django로 쇼핑몰 만들자
Django로 쇼핑몰 만들자Kyoung Up Jung
 
Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기영우 박
 
Djangoフレームワークのユーザーモデルと認証
Djangoフレームワークのユーザーモデルと認証Djangoフレームワークのユーザーモデルと認証
Djangoフレームワークのユーザーモデルと認証Shinya Okano
 
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!
 
Docker 간단 개념 / Docker 를 이용한 MSA 기반의 Spring Boot 프로젝트 - DSmentoring 정다운
Docker 간단 개념 / Docker 를 이용한 MSA 기반의 Spring Boot 프로젝트 - DSmentoring 정다운Docker 간단 개념 / Docker 를 이용한 MSA 기반의 Spring Boot 프로젝트 - DSmentoring 정다운
Docker 간단 개념 / Docker 를 이용한 MSA 기반의 Spring Boot 프로젝트 - DSmentoring 정다운다운 정
 
Webサーバのチューニング
WebサーバのチューニングWebサーバのチューニング
WebサーバのチューニングYu Komiya
 
Présentation de Django @ Orange Labs (FR)
Présentation de Django @ Orange Labs (FR)Présentation de Django @ Orange Labs (FR)
Présentation de Django @ Orange Labs (FR)Martin Latrille
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to djangoIlian Iliev
 
Django Interview Questions and Answers
Django Interview Questions and AnswersDjango Interview Questions and Answers
Django Interview Questions and AnswersPython Devloper
 
Djangoフレームワークの紹介
Djangoフレームワークの紹介Djangoフレームワークの紹介
Djangoフレームワークの紹介Shinya Okano
 
스프링 부트와 로깅
스프링 부트와 로깅스프링 부트와 로깅
스프링 부트와 로깅Keesun Baik
 
Django congress jp 2019 make query great again! (slide share)
Django congress jp 2019 make query great again! (slide share)Django congress jp 2019 make query great again! (slide share)
Django congress jp 2019 make query great again! (slide share)dattun
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Go言語で作る webアプリ@gocon 2013 spring
Go言語で作る webアプリ@gocon 2013 springGo言語で作る webアプリ@gocon 2013 spring
Go言語で作る webアプリ@gocon 2013 springTakuya Ueda
 
애플리케이션 아키텍처와 객체지향
애플리케이션 아키텍처와 객체지향 애플리케이션 아키텍처와 객체지향
애플리케이션 아키텍처와 객체지향 Young-Ho Cho
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)Ishin Vin
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용KyeongMook "Kay" Cha
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
Zend OPcacheの速さの秘密を探る
Zend OPcacheの速さの秘密を探るZend OPcacheの速さの秘密を探る
Zend OPcacheの速さの秘密を探るYoshio Hanawa
 

What's hot (20)

Django로 쇼핑몰 만들자
Django로 쇼핑몰 만들자Django로 쇼핑몰 만들자
Django로 쇼핑몰 만들자
 
Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기
 
Djangoフレームワークのユーザーモデルと認証
Djangoフレームワークのユーザーモデルと認証Djangoフレームワークのユーザーモデルと認証
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...
 
Docker 간단 개념 / Docker 를 이용한 MSA 기반의 Spring Boot 프로젝트 - DSmentoring 정다운
Docker 간단 개념 / Docker 를 이용한 MSA 기반의 Spring Boot 프로젝트 - DSmentoring 정다운Docker 간단 개념 / Docker 를 이용한 MSA 기반의 Spring Boot 프로젝트 - DSmentoring 정다운
Docker 간단 개념 / Docker 를 이용한 MSA 기반의 Spring Boot 프로젝트 - DSmentoring 정다운
 
Webサーバのチューニング
WebサーバのチューニングWebサーバのチューニング
Webサーバのチューニング
 
Présentation de Django @ Orange Labs (FR)
Présentation de Django @ Orange Labs (FR)Présentation de Django @ Orange Labs (FR)
Présentation de Django @ Orange Labs (FR)
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
 
Django Interview Questions and Answers
Django Interview Questions and AnswersDjango Interview Questions and Answers
Django Interview Questions and Answers
 
Djangoフレームワークの紹介
Djangoフレームワークの紹介Djangoフレームワークの紹介
Djangoフレームワークの紹介
 
스프링 부트와 로깅
스프링 부트와 로깅스프링 부트와 로깅
스프링 부트와 로깅
 
Django congress jp 2019 make query great again! (slide share)
Django congress jp 2019 make query great again! (slide share)Django congress jp 2019 make query great again! (slide share)
Django congress jp 2019 make query great again! (slide share)
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Go言語で作る webアプリ@gocon 2013 spring
Go言語で作る webアプリ@gocon 2013 springGo言語で作る webアプリ@gocon 2013 spring
Go言語で作る webアプリ@gocon 2013 spring
 
애플리케이션 아키텍처와 객체지향
애플리케이션 아키텍처와 객체지향 애플리케이션 아키텍처와 객체지향
애플리케이션 아키텍처와 객체지향
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Zend OPcacheの速さの秘密を探る
Zend OPcacheの速さの秘密を探るZend OPcacheの速さの秘密を探る
Zend OPcacheの速さの秘密を探る
 

Similar to 12 tips on Django Best Practices

Decrease build time and application size
Decrease build time and application sizeDecrease build time and application size
Decrease build time and application sizeKeval Patel
 
There is something about serverless
There is something about serverlessThere is something about serverless
There is something about serverlessgjdevos
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with BlackfireMarko Mitranić
 
NoSQL matters in Catchoom Recognition Service
NoSQL matters in Catchoom Recognition ServiceNoSQL matters in Catchoom Recognition Service
NoSQL matters in Catchoom Recognition ServiceCatchoom
 
Creating Developer-Friendly Docker Containers with Chaperone
Creating Developer-Friendly Docker Containers with ChaperoneCreating Developer-Friendly Docker Containers with Chaperone
Creating Developer-Friendly Docker Containers with ChaperoneGary Wisniewski
 
Serverless? How (not) to develop, deploy and operate serverless applications.
Serverless? How (not) to develop, deploy and operate serverless applications.Serverless? How (not) to develop, deploy and operate serverless applications.
Serverless? How (not) to develop, deploy and operate serverless applications.gjdevos
 
Introduction To Django
Introduction To DjangoIntroduction To Django
Introduction To DjangoJay Graves
 
Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)Anand Sampat
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in DjangoLakshman Prasad
 
Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django ArchitectureRami Sayar
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedPromet Source
 
Cache all the things #DCLondon
Cache all the things #DCLondonCache all the things #DCLondon
Cache all the things #DCLondondigital006
 
The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)danwrong
 
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power Tools
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power ToolsSaltConf14 - Thomas Jackson, LinkedIn - Safety with Power Tools
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power ToolsSaltStack
 
Background Processing - PyCon MY 2015
Background Processing - PyCon MY 2015Background Processing - PyCon MY 2015
Background Processing - PyCon MY 2015Kok Hoor Chew
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal PerformancesVladimir Ilic
 

Similar to 12 tips on Django Best Practices (20)

Decrease build time and application size
Decrease build time and application sizeDecrease build time and application size
Decrease build time and application size
 
There is something about serverless
There is something about serverlessThere is something about serverless
There is something about serverless
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
 
NoSQL matters in Catchoom Recognition Service
NoSQL matters in Catchoom Recognition ServiceNoSQL matters in Catchoom Recognition Service
NoSQL matters in Catchoom Recognition Service
 
Creating Developer-Friendly Docker Containers with Chaperone
Creating Developer-Friendly Docker Containers with ChaperoneCreating Developer-Friendly Docker Containers with Chaperone
Creating Developer-Friendly Docker Containers with Chaperone
 
Serverless? How (not) to develop, deploy and operate serverless applications.
Serverless? How (not) to develop, deploy and operate serverless applications.Serverless? How (not) to develop, deploy and operate serverless applications.
Serverless? How (not) to develop, deploy and operate serverless applications.
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Introduction To Django
Introduction To DjangoIntroduction To Django
Introduction To Django
 
Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)Version Control in Machine Learning + AI (Stanford)
Version Control in Machine Learning + AI (Stanford)
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in Django
 
Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django Architecture
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speed
 
Cache all the things #DCLondon
Cache all the things #DCLondonCache all the things #DCLondon
Cache all the things #DCLondon
 
The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)
 
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power Tools
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power ToolsSaltConf14 - Thomas Jackson, LinkedIn - Safety with Power Tools
SaltConf14 - Thomas Jackson, LinkedIn - Safety with Power Tools
 
Background Processing - PyCon MY 2015
Background Processing - PyCon MY 2015Background Processing - PyCon MY 2015
Background Processing - PyCon MY 2015
 
NYC_2016_slides
NYC_2016_slidesNYC_2016_slides
NYC_2016_slides
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal Performances
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 

Recently uploaded

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
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
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: 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
 
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
 

Recently uploaded (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
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
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: 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
 
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
 

12 tips on Django Best Practices

  • 1. 12 tips on Django Best Practices David Arcos catchoom.com | @catchoom
  • 2. 12 tips on Django Best Practices Some (personal) suggestions on: - Development - Deployment - External tools David Arcos | @DZPM Catchoom | http://catchoom.com
  • 3. 12 tips on Django Best Practices Hi! I'm David Arcos - Python/Django developer - discovered Django in 2007 (v0.96) - professionally since 2008 - Web backend, distributed systems, databases, scalability, security - Team leader at Catchoom David Arcos | @DZPM Catchoom | http://catchoom.com
  • 4. 12 tips on Django Best Practices - Image Recognition SaaS - Top recognition results, shortest response times - Easy to integrate into your apps/services David Arcos | @DZPM Catchoom | http://catchoom.com
  • 5. 12 tips on Django Best Practices Why Python? PEP 20, The Zen of Python: - “Beautiful is better than ugly” - “Simple is better than complex” - “Complex is better than complicated” - “Readability counts” - “Special cases aren't special enough to break the rules” - “If the implementation is hard to explain, it's a bad idea” - (…) http://www.python.org/dev/peps/pep-0020/ David Arcos | @DZPM Catchoom | http://catchoom.com
  • 6. 12 tips on Django Best Practices Why Django? - "The Web framework for perfectionists with deadlines" - Django design philosophy: - loose coupling, less code, DRY, consistency, etc... - https://docs.djangoproject.com/en/dev/misc/design-philosophies/ - technically: tons of django apps, very good doc David Arcos | @DZPM Catchoom | http://catchoom.com
  • 7. 12 tips on Django Best Practices Virtualenv: - “one project, one virtualenv” - projects with different dependencies, package versions - easier to deploy. Forget dependency hell! - virtualenvwrapper is a convenient tool David Arcos | @DZPM Catchoom | http://catchoom.com
  • 8. 12 tips on Django Best Practices Dependencies: - use pip: pip install catchoom - save the dependencies in a requirements.txt file: pip freeze > requirements.txt pip install -r requirements.txt David Arcos | @DZPM Catchoom | http://catchoom.com
  • 9. 12 tips on Django Best Practices Layout: projects and apps - project = the full website. app = python library repository/ |-- doc `-- project |-- apps | |-- app1 | |-- app2 | `-- app3 `-- settings David Arcos | @DZPM Catchoom | http://catchoom.com
  • 10. 12 tips on Django Best Practices - use short, obvious, single-word names for your apps - many small apps is better than a few giant apps: - explain an app in a sentence. If you can't, split the app - rather than expand an app, write a new app - don't reinvent the wheel! - django.contrib - 3rd-party apps David Arcos | @DZPM Catchoom | http://catchoom.com
  • 11. 12 tips on Django Best Practices Settings: - multiple settings files: - per environment: dev, testing, staging, production - per developer (local settings, use the hostname) - all settings files must inherit from base, so you can do: INSTALLED_APPS += ('debug_toolbar', ) - version control all the settings! David Arcos | @DZPM Catchoom | http://catchoom.com
  • 12. 12 tips on Django Best Practices Django is a MTV framework - Model (app/models.py) - Template (app/templates/*.html) - View (app/views.py) David Arcos | @DZPM Catchoom | http://catchoom.com
  • 13. 12 tips on Django Best Practices Fat models, thin views... - logic should go to the models (and forms, signals...) - keep the views at a minimum Good example: django.contrib.auth.models.User David Arcos | @DZPM Catchoom | http://catchoom.com
  • 14. 12 tips on Django Best Practices - why? Because of maintainability! - a model is much easier to test - reusable logic: form validation, signals, etc - the code becomes clearer, more self-documenting David Arcos | @DZPM Catchoom | http://catchoom.com
  • 15. 12 tips on Django Best Practices ...and stupid templates! - your template layer should be as thin as possible - (by design) django templates are limited, constrained - doesn't fit your use case? Use jinja2 in those views - Hey, but I get ugly generated HTML! - doesn't matter, you want maintainable templates David Arcos | @DZPM Catchoom | http://catchoom.com
  • 16. 12 tips on Django Best Practices Deployment: - web server: - Nginx + gunicorn - Supervisord to keep it alive. - static server: - Nginx. Or any CDN. David Arcos | @DZPM Catchoom | http://catchoom.com
  • 17. 12 tips on Django Best Practices Fabric: "a library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks" - to automate deployments, migrations, execute management commands, monitoring... - no more repetitive maintainance tasks done manually! David Arcos | @DZPM Catchoom | http://catchoom.com
  • 18. 12 tips on Django Best Practices South: "intelligent schema and data migrations for Django projects" - creates migration files automatically. - You can still do changes - can do backward migrations - will avoid disasters. Use it! David Arcos | @DZPM Catchoom | http://catchoom.com
  • 19. 12 tips on Django Best Practices Celery: "asynchronous task queue/job queue based on distributed message passing" - execute tasks asynchronously, in a pool workers - cpu-intensive or I/O-intensive tasks: - emails, pdfs, thumbnails, crawling, requests... - Celery needs a Message Queue - Instead of RabbitMQ, try Redis. David Arcos | @DZPM Catchoom | http://catchoom.com
  • 20. 12 tips on Django Best Practices Redis: "An advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets." - store ephemeral data (active sessions) - general cache (memcached compatible) - real-time calculations: stats, monitoring, throttling... - messages: channels (pub-sub), lists (push/blpop) - indexes/filters (“sort by hits”) David Arcos | @DZPM Catchoom | http://catchoom.com
  • 21. 12 tips on Django Best Practices Sentry: "realtime event logging and aggregation platform" - monitor errors, get all the info to do a post-mortem - uses the Python logger, easy to configure - deploy a Sentry instance - or use getsentry.com David Arcos | @DZPM Catchoom | http://catchoom.com
  • 22. 12 tips on Django Best Practices Debugging: - ipython (already in ./manage.py shell) - ipdb import ipdb ipdb.set_trace() - django-debug-toolbar - very powerful - use it to optimize db performance, view by view David Arcos | @DZPM Catchoom | http://catchoom.com
  • 23. 12 tips on Django Best Practices Summary: - follow the Django philosophy (when possible) - stand on the shoulder of giants: use existing apps David Arcos | @DZPM Catchoom | http://catchoom.com
  • 24. 12 tips on Django Best Practices Thanks for attending! - http://slideshare.net/DZPM - Questions? David Arcos | @DZPM Catchoom | http://catchoom.com
  • 26. 12 tips on Django Best Practices Thanks for attending! - http://slideshare.net/DZPM David Arcos | @DZPM Catchoom | http://catchoom.com