Djangoを1.11から2.0にバージョンアップ

2017年12月2日にPython用WebフレームワークDjango2.0が正式リリースされました(リリースノート)。実に9年ぶりのメジャーバージョンアップです。

環境

Before After
サーバー AWS EC2
DB PostgreSQL 9.6.5
Python Python 3.6.1
Django Django 1.11.5 Django 2.0.1

 

バージョンアップログ

 

# pip list|grep Django
DEPRECATION: The default format will switch to columns in the future. You can use –format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
Django (1.11.5)
#
#
# pip install Django -U
Collecting Django
Downloading Django-2.0.1-py3-none-any.whl (7.1MB)
100% |████████████████████████████████| 7.1MB 194kB/s
Collecting pytz (from Django)
Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
100% |████████████████████████████████| 512kB 2.6MB/s
Installing collected packages: pytz, Django
Found existing installation: pytz 2017.2
Uninstalling pytz-2017.2:
Successfully uninstalled pytz-2017.2
Found existing installation: Django 1.11.5
Uninstalling Django-1.11.5:
Successfully uninstalled Django-1.11.5
Successfully installed Django-2.0.1 pytz-2017.3
#
#
# pip list|grep Django
DEPRECATION: The default format will switch to columns in the future. You can use –format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
Django (2.0.1)

 

コメント

“pip install Django -U”とコマンド実行してDjangoを最新バージョンにアップデートできました。他には何もしなくても動きます。なお、2.0での一番大きな変更はURLパターンの書き方にdjango.urls.path()を使ったやり方が加わったことだと思います。今までのdjango.conf.urls.url()を使った正規表現よりシンプルにURLパターンを書けます。URLパターンが複雑で正規表現を使いたい場合はdjango.urls.re_path()を使えます。1.11で使っていたdjango.conf.urls.url()はdjango.urls.re_path()に勝手にディスパッチされるのでURL周りを修正しなくても問題ないということでした。

sponsor