A talk I gave at FOSDEM 2011.
The Good, The Bad, & The UglyDjango's Architecture:Andrew GodwinFOSDEM 2011
View Slide
Django core committerMercenary programmerStartup founder (ep.io)
Django: A Brief History
Initial Public Release in 2005
1.0 in 2008
1.3 in a few weeks
Basic Layout
contribcoredbdispatchhttpformsmiddlewareshortcutstemplatesviews
contribadminauthcommentscontenttypesflatpagesgishumanizelocalflavormessagessessionsstaticfilessyndication
corecachefileshandlersmailmanagementserializersserverspaginatorurlresolversvalidators
dbbackends models
othersviews.decoratorsviews.genericcsrftestforms.widgetsforms.fieldsforms.formsetsforms.models
Almost every piece of codehas been changed since 2005
""Good, Bad, Ugly?""
Lessons from both thepast and the present
Some stuff here is historical(we fixed it, thankfully)
There's still nasty bits(we're working on those)
The Good
contrib.admin
admin.site.register(Book,list_display = ["title","slug",],prepopulated_fields = {"slug": ("title","description",)})
The Model Layer(sometimes incorrectly called the ORM)
Sensible Abstractions(sessions, caching, mail, etc.)
GeoDjango(contrib.gis)
from django.contrib.gis.db import modelsclass 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
Debugging Tools(./manage.py shell, testing tools, culture)
CSRF Protection(the new type)
Auto-escaping
View API simplicity
Python
MultiDB
Small actual core
Documentation(both the core docs and the culture)
The Community
Not being too high-level
The Bad
pre-1.2 CSRFWould you like token leakage with that?
...
Schema changesAdd a column? Oh, no, not sure we can do that.
Template ImplementationHasn't changed that much.
The Ugly
""Magic""It's hard to define, but you know itwhen you see it.
Too many regular expressionsThey're great until they're 100+ chars long
(^[-!#$%&'*+/=?^_`{}|~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
Customising AuthCan't really touch it.
{% endifnotequal %}Thankfully we fixed this in 1.2.
Are there lessons to be learnt?
Not everything needs fixing nowA lot of these issues have third-party solutions
How do you get better?Consistency, not always writing new features,and people with too much free time.
Thanks.Andrew Godwin@andrewgodwinhttp://aeracode.org