Fear and Loathing on the Learning Curve: Observations on Life, Tech and Web Design from a Slightly Misanthropic Mind

Notes on upgrad­ing to Django 1.6 and 1.7

Django 1.7 was offi­cially released this week, prompt­ing me to dig into my live Django pro­jects and see which were des­per­ately in need of upgrading.

Fear of get­ting myself into trouble with the new migra­tions sys­tem made me hold back on some pro­jects and upgrade them only as far as 1.6.7, but most pro­jects were bumped all the way to 1.7. Here are a few notes on com­mon changes you might have to make if you’re com­ing from older ver­sions of Django, par­tic­u­larly 1.3 and 1.4.

New migra­tions sys­tem
The most major change intro­duced in 1.7. If your pro­ject uses South migra­tions you’ll need to fol­low the instruc­tions here to gen­er­ate new ini­tial migra­tions for each app in your pro­ject. This seemed to work fine on the pro­jects I upgraded to 1.7.

If you’re upgrad­ing from a ver­sion of Django prior to 1.5, you’ll need to add the ALLOWED_HOSTS vari­able to your set­tings file, or Django will raise a SuspiciousOperation excep­tion when you try to load your site.

New guni­corn init style
I was using an embar­rass­ingly old ver­sion of guni­corn on some pro­jects – 0.12.2, for example; the cur­rent ver­sion is 19.1.1 – and at some point the recom­men­ded init style changed from a man­age­ment com­mand (django-admin.py run_gunicorn or manage.py run_gunicorn) to a stan­dalone com­mand: gunicorn myproject.wsgi. This ref­er­ences the WSGI applic­a­tion defin­i­tion in your project’s wsgi.py cre­ated as part of the pro­ject gen­er­a­tion pro­cess. If your pro­ject was cre­ated prior to Django 1.4, you’ll need to add your own wsgi.py file. Docs here; gen­er­ated code from a sample pro­ject here – replace myproject with your pro­ject name.

You’ll need to change the init style in any pro­cess man­ager you might be using, such as Supervisor, and also in your Procfile if you’re using Heroku. E.g. from this:

web: django-admin.py collectstatic --noinput; django-admin.py run_gunicorn -b "$PORT" -w 4

To this:

web: django-admin.py collectstatic --noinput; gunicorn myproject.wsgi -b "$PORT" -w 4

Adding new style test run­ner
Your test run­ner now needs to be expli­citly declared in your pro­ject set­tings, so I found I needed to add the fol­low­ing set­ting to pre­vent a warn­ing mes­sage (source):

TEST_RUNNER = 'django.test.runner.DiscoverRunner'

Updating {% url %} tem­plate tag style
If you’re upgrad­ing from prior to 1.5, you’ll need to quote route names and view paths passed to the url tem­plate tag – e.g from {% url path.to.your.view %} to {% url ‘path.to.your.view’ %}.

Replacing direct_to_template with TemplateView
Earlier ver­sions of Django sup­por­ted the direct_to_template short­cut to quickly render a tem­plate without a view – this has now been removed in favour of the TemplateView Class-Based View. If you have any URL pat­terns that look like this:

url(r'^404/$', direct_to_template, {'template': '404.html'}),
url(r'^robots\.txt$', direct_to_template, {'template':'robots.txt', 'mimetype':'text/plain’}),

You should replace them with this:

url(r'^404/$', TemplateView.as_view(template_name="404.html”)),
url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain’)),

Virtualenvs los­ing their setuptools
During some lar­ger upgrade runs on my devel­op­ment box, pip would occa­sion­ally drop the ball and refuse to per­form any oper­a­tions, giv­ing the error ImportError: No module named pkg_resources. Reinstalling setuptools using the advice here sor­ted it.

Quickly upgrade all pack­ages in requirements.txt
Lastly, I found for most pro­jects I wanted to upgrade all the pack­ages lis­ted in requirements.txt (which includes pinned ver­sions) — but pip doesn’t yet have a one-stop com­mand for this. I found that some­thing like this usu­ally worked:

cat requirements.txt | grep -v '^-e' | awk 'BEGIN{FS="=="}{print $1}' | xargs echo pip install --upgrade

I’ve since dis­covered the exist­ence of pip-tools which has a com­mand that takes care of this for you.

You’ll prob­ably find a few other bits and pieces that need adjust­ment before your pro­ject will work per­fectly with Django 1.7, but hope­fully this cov­ers some of the more com­mon cases.

The Reckoning of the Finish

A Life Well Wasted – pos­sibly the most thought­ful videogame-related pod­cast ever – is back, and the new epis­ode is some­thing spe­cial. Robert Ashley talks to sev­eral indie game developers about their work, and one quote in par­tic­u­lar – from Greg Wohlwend, one of the developers of Gasketball – struck a chord with me, given what I wrote about fin­ish­ing things last week.

Continued →

Posted March 24th, 2013

Introducing Suncaster, and a few words on fin­ish­ing things

The winter months were get­ting to me recently as they so often do, so last week I released Suncaster, a little app that uses your loc­a­tion and the time you leave work to determ­ine when you’ll next be able to hit the streets before the sun sets (my favour­ite time of day).

Continued →


CSS3 Sprite Animations With Steps()… Almost

I’ve recently been pok­ing around with sprite anim­a­tion for a new ver­sion of this site (more on that later), and since I’m try­ing to show off my cutting-edge front-end chops I wondered if there was a way to accom­plish this anim­a­tion without using JavaScript. And there is! Sort of.

Continued →

Posted November 29th, 2012

Indie Game: The Movie

Yesterday one of my esteemed col­leagues aler­ted me to the recent release of Indie Game: The Movie, so last night I sat down with a friend to watch it. We were both abso­lutely blown away by it. It’s a beau­ti­fully shot doc­u­ment­ary fol­low­ing a few dif­fer­ent developers as they work on or reflect upon their titles – Jonathan Blow talks Braid, the guys from Team Meat hustle to fin­ish Super Meat Boy for its XBLA release, and Phil Fish drags Fez ever closer to its own (now at last arrived) release date.

Continued →

Posted June 14th, 2012

Facebook is Shit

So over the last six months or so I’ve exper­i­enced a sour real­isa­tion. It took me a while to come to terms with it, but I think I can finally sens­ibly express what I’ve dis­covered: Facebook, the increas­ingly omni­present social wünder­kind that I so loved dur­ing my University years is now, in 2012, shit.

Continued →


You can find a complete history of older posts in the Archive.