Online Mind Mapping and Brainstorming

Create your own awesome maps

Online Mind Mapping and Brainstorming

Even on the go

with our free apps for iPhone, iPad and Android

Get Started

Already have an account? Log In

Upgrading to Django 1.3 by Mind Map: Upgrading to Django 1.3
0.0 stars - reviews range from 0 to 5

Upgrading to Django 1.3

better tear-down

Better time-zone support


Use VirtualEnv + pip

VirtualEnv, install, activate

pip, freeze, deps

Strongly recommend to learn them

Douglas: Once you master VirtualEnv, also try VirtualEnvWrapper

Upgrade just Django

pip install --upgrade Django

./ test

Things to watch for (in general), Accessing internals, such as, model._meta, queryset.query, widget, ..., always document doing that, have tests for that code, Arbitrary arguments, such as,, model.delete(), signal handlers, &c, remember **kwargs, protective, Monkeypatches, Prone to break, Deprecated APIs & backward incompatible changes, Check not getting warnings


Upgrade 3rd party apps

Most already support 1.3

Upgrade them 1 by 1

Use pip, Declaratively configure dependencies & versions



command line, pip freeze > requirements.txt, pip install -r requirements.txt

to deal with inconsistency during upgrade, shutdown apache, if you have several servers, upgrade them 1 by 1

Deprecated & removed


(r'^admin/', include(,, part of a large refactoring to make the admin more customizable

Auth backends that don't support anonymous

now they must, class MyAuthBackend(object):, support_object_permissions = False, support_anonymous_user = False, support_inactive_user = False, def authenticate(self, *kw): ...

more here:

Backwards-incompatible changes

Usually due to

security fixes

data-loss bugs

Security fixes

Added CSRF validation for AJAX requests, prior to 1.3 they were exempted from CSRF validations, because it wa assumed that browsers won't allow cross-site scripting, but a Flash vulnerabilyty does expose this risk, $.ajaxSetup({ beforeSend: function(xhr, settings) {, if (!(/^http:.*/.test(settings.url) || https..., xhr.sendRequestHeader("X-CSRFToken", $("#csrfmiddlewaretoken").val());,, Placed restrictions on filters in the admin, Stopped rendering passwords in PasswordInput, Stopped allowing password resets for inactive users

Data-loss bug: FileField file deleteion, but be careful, when cleaning orphan files


Manually-managed transactions need to be expllicitly closed, @transaction.commit_manually

New index on session table, python sqlindexes sessions, will make it faster, Anyway recommends not using db sessions, either memcached, or redis, recommends redis, django-redis-sessions,

The rest

Clearable FileField widget is default

No more PROFANITIES_LIST, in comments, never really worked in the 1st place

Localflavor corrections for Canada, Indonesia & the USA

FormSets can no longer take empty data

Initial SQL files no longer work in tests, use fixtures instead

The new hotness


Improved template tags, {% with total=managers.count name=... %}, {% include "template.html" with total=... %}, {% load my_tag from my_tag_lib %}, {% load url from future %}, {% url "" %}, {% url my_var arg kw=arg2 %}

Class-based generic views, Template view, class HelpView(TemplateView): template_name = "...", url('..', HelpView.as_view()), as_view converts the class to thread-safe object, template name can be provided as argument, Model views, DetailView, class AuthorDetailView(DetailView):, queryset = Author.objects.all(), Base View class, All generic views, You need to extend them, Implementation, Each comprised of mix-ins, Multiple mix-ins trees compose the views, You can construct your own mix-ins, Replacing some mix-ins with our own, See example in docs of JSONDetailView, best-practice, override just the relevant mix-ins, Read about Python's MRO, Method resolution order, > Questions > 3848033 > Getting-current-class-in-method-call, Should you use CBV's?, Wait till there's more experience with it

Model "on delete" options

(Jacob's favorite new feature)

in 1.2 deletes cascade, delete author will delete its books

author = models.ForeignKey(Person, on_delete=models.PROTECT), will throw error when deleting author with books

on_delete=models.DO_NOTHING, leave it to the DB handle it, E.g., MySQL will throw integrity error

on_delete=models.SET_NULL, books Author will be set to null

on_delete=models.SET(get_dummy_person), callback that will be called to set the author field of books, e.g., creates a person called: DELETED

on_delete=<your own callback>, def CASCADE_AND_PRINT(collector, field, sub_objs, using):, print "Deleting", sub_objs, return models.CASCADE(collector, field, sub_objs, using)


unittest2, will be part of 2.7, bundled in 1.3, vastly improved failure messages, shows smart diff of, lists, sets, dictionaries, text, skipping tests, @unittest.skipIf(platform.system() != 'Linux', "only works on linux"), skip, skipIf, skipUnless(condition, 'skipped if not condition'), skipIfDBFeature('supports_transactions'), skipUnlessDBFeature, assertRaises context manager, class & module level setUp/tearDown, usage, from django.test import TestCase, or, from django.util import unittest, class MyTest(TestCase):,

RequestFactory, in 1.2, r = self.client.get('/some/view'), self.assertEqual(r.status_code, 200), in 1,3, rf = django.test.client.RequestFactory(), request = rf.get('/some/view'), response = some_view(request), self.assertEqual(response.status_code, 200), directly invokes view, without the full stack, middleware &c, Jacob says he'll now write view tests like this

assertNumQueries, with self.assertNumQueries(2):, self.client.get('/some/view/')


Multiple caches, settings.CACHES, like databases, old syntax still work, but at some point you'll need to upgrade, syntax, CACHES = {, 'default': {, 'BACKEND': 'django.core.cache.backends.memecached.PyLibMC, 'KEY_PREFIX': 'mysite', 'VERSION': 1,, 'second': {, c1 = cache.get_cache('default'), c1.set(...), changing version will invalidate all previous cache, there's a python API to change the version


site-wide prefixing


pylibmc support, new & much faster memcached

Suggestions:, switch to pylibmc, enable versioning

Static files

clears confusion

Definitions, "media", files uploaded by users, FileField, ImageField, "static", static assets that are part of your site, "files", either of the above

pluggable apps have their own static files

new contrib app, django.contrib.staticfiles, collects static files from multiple apps into a central location, & just that

usage, in developement, add to INSTALLED_APPS, put static files in, <app>/static, set STATIC_URL to "/static/", in production, use dedicated media server, nginx, STATIC_ROOT = '/var/www/static/', STATIC_URL = '', ./ collectstatic

in templates, {% load static %}, ..., see docs

Suggestion, Switch if your current scheme makes you unhappy

There are more 3rd party apps with more features, compression, sprites, caching, &c, see in, > Grids > G > Asset-managers, django-storages, use S3 &c

Everything else

Logging, built-in support for Python logging,, Read docs - really good intro

TemplateResponse, similar to HttpResponse, yet Lazy, easier to do manipulations before rendering, decorators, middleware,

django.shortcuts.render(), can use the requst processor, use it

Transactions as context managers

"Pretty" error emails, like the debug pages

"Current site" helper, get_current_site

HTTPOnly cookies,

Context-aware simple tags

What's coming next

Planning for deprecation

to be removed in 1.4, Python 2.4 support, single-db support, User-based messages, user.message_set.create(), replaced by django.contrib.messages, Legacy auth backends, supports_anonymous_user &c must be true, & more

to be removed in 1.5, Python 2.5 support (?), 2.6 much faster, mod_python support, you can't event download it anymore, use mod_wsgi, Function based generic views, Old style url & ssi template tags

New features (speculations)

Basic schema migration support, bringing basic low level south api's

Refactor & formalization of "apps"

Improved ideas of what a "user" is

Better hooks for monitoring, debugging, metrics

Template compilation, speed improvements

Python 3 support, experimental probably