Slide 1

Slide 1 text

django unleashed - Saket Bhushan @gamebit07

Slide 2

Slide 2 text

Topics Covered ● Setting up your environment ● Project Scaffolding ● Overview of django ● Dive into Settings File ● Take some Notes ● Testing your application ● Some best practices ● Example Repo [https://github. com/fRuiApps/djbp]

Slide 3

Slide 3 text

Topics not Covered ● Documenting your Code ● Deploying your Code ● Performance Benchmarking & Optimization ● Django Forms

Slide 4

Slide 4 text

Your Environment ● Isolation ● Determinism ● Similarity ● pip ● virtualenv ● virtualenvwrapper Tutorial

Slide 5

Slide 5 text

Your Environment ● sudo apt-get install python-setuptools python-dev build-essential ● easy_install -U pip ● pip install virtualenv virtualenvwrapper ● requirements file ○ local ○ test ○ production

Slide 6

Slide 6 text

The Fountain Analogy http://www.flickr.com/photos/paparutzi/208664919/

Slide 7

Slide 7 text

Some of Django

Slide 8

Slide 8 text

Some of Django

Slide 9

Slide 9 text

Installation & Getting Started ● pip install -r requirements/test.txt ● pip install -r requirements/local.txt ● django-admin.py startproject djnotes ● python manage.py startapp noteapp -- settings=djnotes.settings.local

Slide 10

Slide 10 text

Project Structure ├── djnotes │ └── settings ├── noteapp │ ├── migrations │ ├── templates │ └── tests ├── static │ ├── css │ ├── img │ └── js │ ├── lib │ └── modules └── templates

Slide 11

Slide 11 text

Settings File ● Settings under version control ● Use Relative Path ○ no hardcoded paths eg. /home/betaversion/... ● Keep secret keys Secret ● Different Settings for different environment ● Custom Middlewares & ContextProcessors in a try catch block ● local_settings.py is an AntiPattern

Slide 12

Slide 12 text

Some more of Django ● Views - Presentation Logic ● Models - Business Logic ● Templates - Presentation Layer

Slide 13

Slide 13 text

Demo

Slide 14

Slide 14 text

RTF Code

Slide 15

Slide 15 text

Intro to TDD ● Unit vs Integration Test ● Test Runner ● What all to test? Detailed Article(s) on TDD Slides from my PyCon talk on TDD

Slide 16

Slide 16 text

Run Some Tests

Slide 17

Slide 17 text

Read Some Tests

Slide 18

Slide 18 text

Some minimal best practices ● Models ○ The database fields should be names as first_name and NOT FirstName. ○ The database table names(class names) should be named as ClassNames and not class_names ○ There should be a unicode method for each of the classes.

Slide 19

Slide 19 text

Some minimal best practices ● Templates ○ One base.html at the project level, and one base. html at each of the app levels. ○ App level base.html should extend the project level base.html ○ The variable in templates should have spaces between the name and bracket. Eg. {{ variable }} and NOT {{variable}}

Slide 20

Slide 20 text

Some minimal best practices ● urls ○ design pretty urls ■ use slugs instead of primary keys ○ Each of the urls should have a name, corresponding to the view name. ○ There should be one urls.py at the project level, and one urls.py at each app level. The project level urls. py should include each of the urls.py under a prefix. Further Reading

Slide 21

Slide 21 text

Thanks & Questions gmail - gamebit07 at gmail dot com twitter - @gamebit07