Quantcast
Channel: Peter of the Norse Thinks He’s Smarter than You
Viewing all articles
Browse latest Browse all 54

Moving from Django 1.4 to 1.8

0
0

I’m currently in the process of moving from Django 1.4 to 1.8 and Python 2.7 to 3.4. The main reason I’m writing this is so that someone else making the same changes doesn’t need to work too hard.

This is one of my gripes about the Django Foundation. They don’t consider that there will be a fair number of projects jumping from one long term support to another. Instead, they recommend going from 1.4 to 1.5 to 1.6 to 1.7 to 1.8. That ain’t fun. The only thing I was able to find is a Guide to updating to 1.7.


Upgrading Python from 2 to 3

Of course the first step to any change like this is creating a new virtual environment and branching your CVS. Since I’m moving to py3k, I’m going to use the built-in pyvenv. There are some arguments for using the good old virtualenv, but I’m trying to keep it as clean as possible.

You’ll want to make sure that you’re using the most up-to-date version of your DB and other support libraries. Update your requirements.txt so that it pulls the latest version of addons.

There’s a good guide to moving from Python 2 to 3. Since I’m not going to worry about backwards compatibility, I can just run 2to3 and rename all of the functions. You can’t do it first and then test because 1.4 doesn’t have any py3k compatibility, but it’s so simple that you can do it at almost any point.


Actually upgrading Django requires taking a look at 1.5, 1.6, 1.7, 1.8, and the deprecation timeline. This is what I call obnoxious. The entire point of writing this is so that we can consolidate all of the changes that need to be made in one place with simple language step by step directions. Let’s get into it.

Changes to settings.py

  • Templates is now a list of backends with some settings for each. While this isn’t necessary for right now, it’s going away in 1.11.
  • ALLOWED_HOSTS is now required
  • Many settings have been removed. Look through your settings file and find what they’ve been changed to.

Changes to templates

  • You can remove {% load url from future %}. If you haven’t been using it, then you need to update your {%url%} tags.
  • {%cycle%} and {%firstof%} now autoescape.

Changes to code

  • django.conf.urls.defaults is now django.conf.urls.
  • Everywhere that was query_set is now queryset.
  • Same with mimetype becoming content_type.
  • django.utils.simplejson is dead. You can just use the Python json instead.
  • ValidationError has a completely different format. If you were dealing with multiple errors, that’s changed.
  • ModelForms now require an explicit _Meta.exclude=().
  • Transaction management has completely changed. You’ll have to change most of it.

django.contrib sections removed

  • django.contrib.comments
  • django.contrib.gis.sitemaps
  • django.contrib.databrowse
  • django.contrib.localflavor
  • django.contrib.markup

Viewing all articles
Browse latest Browse all 54

Latest Images

Trending Articles





Latest Images