Slide 1

Slide 1 text

The Good, The Bad, & The Ugly Django's Architecture: Andrew Godwin FOSDEM 2011

Slide 2

Slide 2 text

Django core committer Mercenary programmer Startup founder (ep.io)

Slide 3

Slide 3 text

Django: A Brief History

Slide 4

Slide 4 text

Initial Public Release in 2005

Slide 5

Slide 5 text

1.0 in 2008

Slide 6

Slide 6 text

1.3 in a few weeks

Slide 7

Slide 7 text

Basic Layout

Slide 8

Slide 8 text

contrib core db dispatch http forms middleware shortcuts templates views

Slide 9

Slide 9 text

contrib admin auth comments contenttypes flatpages gis humanize localflavor messages sessions staticfiles syndication

Slide 10

Slide 10 text

core cache files handlers mail management serializers servers paginator urlresolvers validators

Slide 11

Slide 11 text

db backends models

Slide 12

Slide 12 text

others views.decorators views.generic csrf test forms.widgets forms.fields forms.formsets forms.models

Slide 13

Slide 13 text

Almost every piece of code has been changed since 2005

Slide 14

Slide 14 text

""Good, Bad, Ugly?""

Slide 15

Slide 15 text

Lessons from both the past and the present

Slide 16

Slide 16 text

Some stuff here is historical (we fixed it, thankfully)

Slide 17

Slide 17 text

There's still nasty bits (we're working on those)

Slide 18

Slide 18 text

The Good

Slide 19

Slide 19 text

contrib.admin

Slide 20

Slide 20 text

admin.site.register( Book, list_display = [ "title", "slug", ], prepopulated_fields = { "slug": ( "title", "description", ) } )

Slide 21

Slide 21 text

The Model Layer (sometimes incorrectly called the ORM)

Slide 22

Slide 22 text

Sensible Abstractions (sessions, caching, mail, etc.)

Slide 23

Slide 23 text

GeoDjango (contrib.gis)

Slide 24

Slide 24 text

from django.contrib.gis.db import models class Lakes(models.Model): name = models.CharField(max_length=100) rate = models.IntegerField() geom = models.MultiPolygonField() objects = models.GeoManager() >>> lake3 = Lakes.objects.get(id=3) >>> newlake.geom.contains(lake3.geom) True

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Debugging Tools (./manage.py shell, testing tools, culture)

Slide 27

Slide 27 text

CSRF Protection (the new type)

Slide 28

Slide 28 text

Auto-escaping

Slide 29

Slide 29 text

View API simplicity

Slide 30

Slide 30 text

Python

Slide 31

Slide 31 text

MultiDB

Slide 32

Slide 32 text

Small actual core

Slide 33

Slide 33 text

Documentation (both the core docs and the culture)

Slide 34

Slide 34 text

The Community

Slide 35

Slide 35 text

Not being too high-level

Slide 36

Slide 36 text

The Bad

Slide 37

Slide 37 text

pre-1.2 CSRF Would you like token leakage with that?

Slide 38

Slide 38 text

...

Slide 39

Slide 39 text

...

Slide 40

Slide 40 text

...

Slide 41

Slide 41 text

Schema changes Add a column? Oh, no, not sure we can do that.

Slide 42

Slide 42 text

Template Implementation Hasn't changed that much.

Slide 43

Slide 43 text

The Ugly

Slide 44

Slide 44 text

""Magic"" It's hard to define, but you know it when you see it.

Slide 45

Slide 45 text

Too many regular expressions They're great until they're 100+ chars long

Slide 46

Slide 46 text

(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)* # dot-atom |^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*" # quoted-string )@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$' # domain (^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)* # dot-atom |^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*" # quoted-string )@(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}$ # domain

Slide 47

Slide 47 text

Customising Auth Can't really touch it.

Slide 48

Slide 48 text

{% endifnotequal %} Thankfully we fixed this in 1.2.

Slide 49

Slide 49 text

Are there lessons to be learnt?

Slide 50

Slide 50 text

Not everything needs fixing now A lot of these issues have third-party solutions

Slide 51

Slide 51 text

How do you get better? Consistency, not always writing new features, and people with too much free time.

Slide 52

Slide 52 text

Thanks. Andrew Godwin @andrewgodwin http://aeracode.org