2014-10-06

Migrating from Django 1.6 to 1.7

Recently I upgraded a simple Django project from Django 1.6 (running on Python 2.7) to Django 1.7 (running on Python 3.4). Below are some of the steps taken.
1. Switch to new syntax of relative import

OLD> from local_setting import *
NEW> from .local_setting import *

2. Change HttpResponse() argument from mimetype to content_type

OLD> response = HttpResponse(mimetype='text/csv')
NEW> response = HttpResponse(content_type='text/csv')

3. Specify binary mode in open() to avoid UnicodeDecodeError

OLD> with open("binary_file") as
NEW> with open("binary_file", "rb") as

4. Replace __unicode__() with __str__()

OLD> def __unicode__(self):
NEW> def __str__(self):

I also updated my .vimrc to exclude the __pycache__ directories from showing up in netrw.
=== ~/.vimrc ===

let g:netrw_list_hide= '.*\.pyc$,.*\.swp$,__pycache__'

No comments: