読者です 読者をやめる 読者になる 読者になる

ぼくの技術日誌

日誌って銘打っていますが、更新頻度が…

HerokuにDjangoアプリをデプロイしてみた

heroku django python

はじめに

LINE Messaging APIを使ってBotを作ってみたいと思い、これまた以前から使ってみたかったHerokuにDjangoアプリをデプロイしてみました。
なお、Djangoは使うのも初めてで、選んだ理由は特にはありません。
基本的にUbuntu 14.04 で Django アプリケーションを Heroku にデプロイする手順 | dreamin'up4uに書いてくださった内容を試しただけです。
ただ、Herokuへアプリのgitリポジトリをpushするところでエラーが発生し、解決するのに少し苦労しました。


この記事の実行環境は下記のとおりです。

Django開発環境の構築

まずは開発環境を構築します。

yosuke@yosuke-vm:~$ wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | shThis script requires superuser access to install apt packages.
You will be prompted for your password by sudo.
[sudo] password for yosuke: 
--2016-11-02 11:29:33--  https://toolbelt.heroku.com/apt/release.key
Resolving toolbelt.heroku.com (toolbelt.heroku.com)... 50.16.189.161, 107.20.254.176, 54.243.84.197
Connecting to toolbelt.heroku.com (toolbelt.heroku.com)|50.16.189.161|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1737 (1.7K) [application/octet-stream]
Saving to: ‘STDOUT’

-                   100%[===================>]   1.70K  --.-KB/s    in 0s      

2016-11-02 11:29:34 (256 MB/s) - written to stdout [1737/1737]

OK
Hit:1 http://jp.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://jp.archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]   
Get:3 http://jp.archive.ubuntu.com/ubuntu xenial-backports InRelease [92.2 kB] 
Get:4 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [417 kB]
Get:6 http://security.ubuntu.com/ubuntu xenial-security InRelease [94.5 kB]    
Get:7 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages [412 kB]
Ign:5 http://toolbelt.heroku.com/ubuntu ./ InRelease                           
Get:8 http://jp.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [357 kB]
Get:10 http://jp.archive.ubuntu.com/ubuntu xenial-updates/universe i386 Packages [353 kB]
Get:9 http://toolbelt.heroku.com/ubuntu ./ Release [1,609 B]                   
Get:11 http://security.ubuntu.com/ubuntu xenial-security/main amd64 DEP-11 Metadata [79.1 kB]
Get:12 http://toolbelt.heroku.com/ubuntu ./ Release.gpg [473 B]   
Get:13 http://security.ubuntu.com/ubuntu xenial-security/main DEP-11 64x64 Icons [62.9 kB]
Get:14 http://toolbelt.heroku.com/ubuntu ./ Packages [725 B] 
Get:15 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 DEP-11 Metadata [7,420 B]
Fetched 1,973 kB in 2s (679 kB/s)                               
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  fonts-lato git git-core git-man heroku javascript-common liberror-perl
  libjs-jquery libruby2.3 rake ruby ruby-did-you-mean ruby-minitest
  ruby-net-telnet ruby-power-assert ruby-test-unit ruby2.3
  rubygems-integration
Suggested packages:
  git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk
  gitweb git-arch git-cvs git-mediawiki git-svn apache2 | lighttpd | httpd ri
  ruby-dev bundler
The following NEW packages will be installed:
  fonts-lato git git-core git-man heroku heroku-toolbelt javascript-common
  liberror-perl libjs-jquery libruby2.3 rake ruby ruby-did-you-mean
  ruby-minitest ruby-net-telnet ruby-power-assert ruby-test-unit ruby2.3
  rubygems-integration
0 upgraded, 19 newly installed, 0 to remove and 8 not upgraded.
Need to get 11.6 MB of archives.
After this operation, 53.0 MB of additional disk space will be used.
Get:1 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 fonts-lato all 2.0-1 [2,693 kB]
Get:2 http://toolbelt.heroku.com/ubuntu ./ heroku 3.43.13 [1,836 kB]           
Get:4 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 rubygems-integration all 1.10 [4,966 B]
Get:5 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 ruby all 1:2.3.0+1 [5,530 B]
Get:6 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 rake all 10.5.0-2 [48.2 kB]
Get:7 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 ruby-did-you-mean all 1.0.0-2 [8,390 B]
Get:8 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 ruby-minitest all 5.8.4-2 [36.6 kB]
Get:9 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 ruby-net-telnet all 0.1.1-2 [12.6 kB]
Get:10 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 ruby-power-assert all 0.2.7-1 [7,668 B]
Get:11 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 ruby-test-unit all 3.1.7-2 [60.3 kB]
Get:12 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libruby2.3 amd64 2.3.1-2~16.04 [2,957 kB]
Get:13 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 ruby2.3 amd64 2.3.1-2~16.04 [40.9 kB]
Get:14 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 liberror-perl all 0.17-1.2 [19.6 kB]
Get:15 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 git-man all 1:2.7.4-0ubuntu1 [735 kB]
Get:16 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 git amd64 1:2.7.4-0ubuntu1 [3,006 kB]
Get:3 http://toolbelt.heroku.com/ubuntu ./ heroku-toolbelt 3.43.13 [668 B]
Get:17 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 git-core all 1:2.7.4-0ubuntu1 [1,464 B]
Get:18 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 javascript-common all 11 [6,066 B]
Get:19 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 libjs-jquery all 1.11.3+dfsg-4 [161 kB]
Fetched 11.6 MB in 6s (1,702 kB/s)                                             
Selecting previously unselected package fonts-lato.
(Reading database ... 204882 files and directories currently installed.)
Preparing to unpack .../fonts-lato_2.0-1_all.deb ...
Unpacking fonts-lato (2.0-1) ...
Selecting previously unselected package rubygems-integration.
Preparing to unpack .../rubygems-integration_1.10_all.deb ...
Unpacking rubygems-integration (1.10) ...
Selecting previously unselected package ruby.
Preparing to unpack .../ruby_1%3a2.3.0+1_all.deb ...
Unpacking ruby (1:2.3.0+1) ...
Selecting previously unselected package rake.
Preparing to unpack .../archives/rake_10.5.0-2_all.deb ...
Unpacking rake (10.5.0-2) ...
Selecting previously unselected package ruby-did-you-mean.
Preparing to unpack .../ruby-did-you-mean_1.0.0-2_all.deb ...
Unpacking ruby-did-you-mean (1.0.0-2) ...
Selecting previously unselected package ruby-minitest.
Preparing to unpack .../ruby-minitest_5.8.4-2_all.deb ...
Unpacking ruby-minitest (5.8.4-2) ...
Selecting previously unselected package ruby-net-telnet.
Preparing to unpack .../ruby-net-telnet_0.1.1-2_all.deb ...
Unpacking ruby-net-telnet (0.1.1-2) ...
Selecting previously unselected package ruby-power-assert.
Preparing to unpack .../ruby-power-assert_0.2.7-1_all.deb ...
Unpacking ruby-power-assert (0.2.7-1) ...
Selecting previously unselected package ruby-test-unit.
Preparing to unpack .../ruby-test-unit_3.1.7-2_all.deb ...
Unpacking ruby-test-unit (3.1.7-2) ...
Selecting previously unselected package libruby2.3:amd64.
Preparing to unpack .../libruby2.3_2.3.1-2~16.04_amd64.deb ...
Unpacking libruby2.3:amd64 (2.3.1-2~16.04) ...
Selecting previously unselected package ruby2.3.
Preparing to unpack .../ruby2.3_2.3.1-2~16.04_amd64.deb ...
Unpacking ruby2.3 (2.3.1-2~16.04) ...
Selecting previously unselected package heroku.
Preparing to unpack .../heroku_3.43.13_all.deb ...
Unpacking heroku (3.43.13) ...
Selecting previously unselected package liberror-perl.
Preparing to unpack .../liberror-perl_0.17-1.2_all.deb ...
Unpacking liberror-perl (0.17-1.2) ...
Selecting previously unselected package git-man.
Preparing to unpack .../git-man_1%3a2.7.4-0ubuntu1_all.deb ...
Unpacking git-man (1:2.7.4-0ubuntu1) ...
Selecting previously unselected package git.
Preparing to unpack .../git_1%3a2.7.4-0ubuntu1_amd64.deb ...
Unpacking git (1:2.7.4-0ubuntu1) ...
Selecting previously unselected package git-core.
Preparing to unpack .../git-core_1%3a2.7.4-0ubuntu1_all.deb ...
Unpacking git-core (1:2.7.4-0ubuntu1) ...
Selecting previously unselected package heroku-toolbelt.
Preparing to unpack .../heroku-toolbelt_3.43.13_all.deb ...
Unpacking heroku-toolbelt (3.43.13) ...
Selecting previously unselected package javascript-common.
Preparing to unpack .../javascript-common_11_all.deb ...
Unpacking javascript-common (11) ...
Selecting previously unselected package libjs-jquery.
Preparing to unpack .../libjs-jquery_1.11.3+dfsg-4_all.deb ...
Unpacking libjs-jquery (1.11.3+dfsg-4) ...
Processing triggers for fontconfig (2.11.94-0ubuntu1.1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for libc-bin (2.23-0ubuntu4) ...
Setting up fonts-lato (2.0-1) ...
Setting up rubygems-integration (1.10) ...
Setting up ruby-did-you-mean (1.0.0-2) ...
Setting up ruby-minitest (5.8.4-2) ...
Setting up ruby-net-telnet (0.1.1-2) ...
Setting up ruby-power-assert (0.2.7-1) ...
Setting up ruby-test-unit (3.1.7-2) ...
Setting up liberror-perl (0.17-1.2) ...
Setting up git-man (1:2.7.4-0ubuntu1) ...
Setting up git (1:2.7.4-0ubuntu1) ...
Setting up git-core (1:2.7.4-0ubuntu1) ...
Setting up javascript-common (11) ...
Setting up libjs-jquery (1.11.3+dfsg-4) ...
Setting up rake (10.5.0-2) ...
Setting up libruby2.3:amd64 (2.3.1-2~16.04) ...
Setting up ruby2.3 (2.3.1-2~16.04) ...
Setting up ruby (1:2.3.0+1) ...
Setting up heroku (3.43.13) ...
Setting up heroku-toolbelt (3.43.13) ...
Processing triggers for libc-bin (2.23-0ubuntu4) ...
yosuke@yosuke-vm:~$ heroku -v
heroku-cli: Installing CLI... 2.92MB/22.45MB^C !    Command cancelled.
yosuke@yosuke-vm:~$ heroku version
heroku-cli: Installing CLI... 22.45MB/22.45MB
heroku-toolbelt/3.43.13 (x86_64-linux-gnu) ruby/2.3.1
heroku-cli/5.4.8-eee5ec9 (linux-amd64) go1.7.1
You have no installed plugins.
yosuke@yosuke-vm:~$ sudo apt-get install python-pip python-virtualenv libpq-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  comerr-dev krb5-multidev libexpat1-dev libgssrpc4 libkadm5clnt-mit9
  libkadm5srv-mit9 libkdb5-8 libpq5 libpython-all-dev libpython-dev
  libpython2.7-dev libssl-dev libssl-doc python-all python-all-dev python-dev
  python-pip-whl python-pkg-resources python-setuptools python-wheel
  python2.7-dev python3-virtualenv virtualenv zlib1g-dev
Suggested packages:
  krb5-doc krb5-user postgresql-doc-9.5 python-setuptools-doc
The following NEW packages will be installed:
  comerr-dev krb5-multidev libexpat1-dev libgssrpc4 libkadm5clnt-mit9
  libkadm5srv-mit9 libkdb5-8 libpq-dev libpq5 libpython-all-dev libpython-dev
  libpython2.7-dev libssl-dev libssl-doc python-all python-all-dev python-dev
  python-pip python-pip-whl python-pkg-resources python-setuptools
  python-virtualenv python-wheel python2.7-dev python3-virtualenv virtualenv
  zlib1g-dev
0 upgraded, 27 newly installed, 0 to remove and 8 not upgraded.
Need to get 33.0 MB of archives.
After this operation, 58.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 libgssrpc4 amd64 1.13.2+dfsg-5 [54.4 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 libkdb5-8 amd64 1.13.2+dfsg-5 [37.1 kB]
Get:3 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 libkadm5srv-mit9 amd64 1.13.2+dfsg-5 [51.1 kB]
Get:4 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 libkadm5clnt-mit9 amd64 1.13.2+dfsg-5 [36.5 kB]
Get:5 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 comerr-dev amd64 2.1-1.42.13-1ubuntu1 [38.2 kB]
Get:6 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 krb5-multidev amd64 1.13.2+dfsg-5 [113 kB]
Get:7 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libexpat1-dev amd64 2.1.0-7ubuntu0.16.04.2 [115 kB]
Get:8 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpq5 amd64 9.5.4-0ubuntu0.16.04 [77.8 kB]
Get:9 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 zlib1g-dev amd64 1:1.2.8.dfsg-2ubuntu4 [168 kB]
Get:10 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libssl-dev amd64 1.0.2g-1ubuntu4.5 [1,344 kB]
Get:11 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpq-dev amd64 9.5.4-0ubuntu0.16.04 [154 kB]
Get:12 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpython2.7-dev amd64 2.7.12-1~16.04 [27.8 MB]
Get:13 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 libpython-dev amd64 2.7.11-1 [7,728 B]
Get:14 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 libpython-all-dev amd64 2.7.11-1 [992 B]
Get:15 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libssl-doc all 1.0.2g-1ubuntu4.5 [1,078 kB]
Get:16 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-all amd64 2.7.11-1 [978 B]
Get:17 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 python2.7-dev amd64 2.7.12-1~16.04 [276 kB]
Get:18 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-dev amd64 2.7.11-1 [1,160 B]
Get:19 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-all-dev amd64 2.7.11-1 [1,000 B]
Get:20 http://jp.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 python-pip-whl all 8.1.1-2ubuntu0.2 [1,111 kB]
Get:21 http://jp.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 python-pip all 8.1.1-2ubuntu0.2 [144 kB]
Get:22 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-pkg-resources all 20.7.0-1 [108 kB]
Get:23 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-setuptools all 20.7.0-1 [169 kB]
Get:24 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 python-virtualenv all 15.0.1+ds-3 [46.7 kB]
Get:25 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 python-wheel all 0.29.0-1 [48.0 kB]
Get:26 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 python3-virtualenv all 15.0.1+ds-3 [43.3 kB]
Get:27 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 virtualenv all 15.0.1+ds-3 [4,342 B]
Fetched 33.0 MB in 24s (1,334 kB/s)                                            
Selecting previously unselected package libgssrpc4:amd64.
(Reading database ... 208100 files and directories currently installed.)
Preparing to unpack .../libgssrpc4_1.13.2+dfsg-5_amd64.deb ...
Unpacking libgssrpc4:amd64 (1.13.2+dfsg-5) ...
Selecting previously unselected package libkdb5-8:amd64.
Preparing to unpack .../libkdb5-8_1.13.2+dfsg-5_amd64.deb ...
Unpacking libkdb5-8:amd64 (1.13.2+dfsg-5) ...
Selecting previously unselected package libkadm5srv-mit9:amd64.
Preparing to unpack .../libkadm5srv-mit9_1.13.2+dfsg-5_amd64.deb ...
Unpacking libkadm5srv-mit9:amd64 (1.13.2+dfsg-5) ...
Selecting previously unselected package libkadm5clnt-mit9:amd64.
Preparing to unpack .../libkadm5clnt-mit9_1.13.2+dfsg-5_amd64.deb ...
Unpacking libkadm5clnt-mit9:amd64 (1.13.2+dfsg-5) ...
Selecting previously unselected package comerr-dev.
Preparing to unpack .../comerr-dev_2.1-1.42.13-1ubuntu1_amd64.deb ...
Unpacking comerr-dev (2.1-1.42.13-1ubuntu1) ...
Selecting previously unselected package krb5-multidev.
Preparing to unpack .../krb5-multidev_1.13.2+dfsg-5_amd64.deb ...
Unpacking krb5-multidev (1.13.2+dfsg-5) ...
Selecting previously unselected package libexpat1-dev:amd64.
Preparing to unpack .../libexpat1-dev_2.1.0-7ubuntu0.16.04.2_amd64.deb ...
Unpacking libexpat1-dev:amd64 (2.1.0-7ubuntu0.16.04.2) ...
Selecting previously unselected package libpq5:amd64.
Preparing to unpack .../libpq5_9.5.4-0ubuntu0.16.04_amd64.deb ...
Unpacking libpq5:amd64 (9.5.4-0ubuntu0.16.04) ...
Selecting previously unselected package zlib1g-dev:amd64.
Preparing to unpack .../zlib1g-dev_1%3a1.2.8.dfsg-2ubuntu4_amd64.deb ...
Unpacking zlib1g-dev:amd64 (1:1.2.8.dfsg-2ubuntu4) ...
Selecting previously unselected package libssl-dev:amd64.
Preparing to unpack .../libssl-dev_1.0.2g-1ubuntu4.5_amd64.deb ...
Unpacking libssl-dev:amd64 (1.0.2g-1ubuntu4.5) ...
Selecting previously unselected package libpq-dev.
Preparing to unpack .../libpq-dev_9.5.4-0ubuntu0.16.04_amd64.deb ...
Unpacking libpq-dev (9.5.4-0ubuntu0.16.04) ...
Selecting previously unselected package libpython2.7-dev:amd64.
Preparing to unpack .../libpython2.7-dev_2.7.12-1~16.04_amd64.deb ...
Unpacking libpython2.7-dev:amd64 (2.7.12-1~16.04) ...
Selecting previously unselected package libpython-dev:amd64.
Preparing to unpack .../libpython-dev_2.7.11-1_amd64.deb ...
Unpacking libpython-dev:amd64 (2.7.11-1) ...
Selecting previously unselected package libpython-all-dev:amd64.
Preparing to unpack .../libpython-all-dev_2.7.11-1_amd64.deb ...
Unpacking libpython-all-dev:amd64 (2.7.11-1) ...
Selecting previously unselected package libssl-doc.
Preparing to unpack .../libssl-doc_1.0.2g-1ubuntu4.5_all.deb ...
Unpacking libssl-doc (1.0.2g-1ubuntu4.5) ...
Selecting previously unselected package python-all.
Preparing to unpack .../python-all_2.7.11-1_amd64.deb ...
Unpacking python-all (2.7.11-1) ...
Selecting previously unselected package python2.7-dev.
Preparing to unpack .../python2.7-dev_2.7.12-1~16.04_amd64.deb ...
Unpacking python2.7-dev (2.7.12-1~16.04) ...
Selecting previously unselected package python-dev.
Preparing to unpack .../python-dev_2.7.11-1_amd64.deb ...
Unpacking python-dev (2.7.11-1) ...
Selecting previously unselected package python-all-dev.
Preparing to unpack .../python-all-dev_2.7.11-1_amd64.deb ...
Unpacking python-all-dev (2.7.11-1) ...
Selecting previously unselected package python-pip-whl.
Preparing to unpack .../python-pip-whl_8.1.1-2ubuntu0.2_all.deb ...
Unpacking python-pip-whl (8.1.1-2ubuntu0.2) ...
Selecting previously unselected package python-pip.
Preparing to unpack .../python-pip_8.1.1-2ubuntu0.2_all.deb ...
Unpacking python-pip (8.1.1-2ubuntu0.2) ...
Selecting previously unselected package python-pkg-resources.
Preparing to unpack .../python-pkg-resources_20.7.0-1_all.deb ...
Unpacking python-pkg-resources (20.7.0-1) ...
Selecting previously unselected package python-setuptools.
Preparing to unpack .../python-setuptools_20.7.0-1_all.deb ...
Unpacking python-setuptools (20.7.0-1) ...
Selecting previously unselected package python-virtualenv.
Preparing to unpack .../python-virtualenv_15.0.1+ds-3_all.deb ...
Unpacking python-virtualenv (15.0.1+ds-3) ...
Selecting previously unselected package python-wheel.
Preparing to unpack .../python-wheel_0.29.0-1_all.deb ...
Unpacking python-wheel (0.29.0-1) ...
Selecting previously unselected package python3-virtualenv.
Preparing to unpack .../python3-virtualenv_15.0.1+ds-3_all.deb ...
Unpacking python3-virtualenv (15.0.1+ds-3) ...
Selecting previously unselected package virtualenv.
Preparing to unpack .../virtualenv_15.0.1+ds-3_all.deb ...
Unpacking virtualenv (15.0.1+ds-3) ...
Processing triggers for libc-bin (2.23-0ubuntu4) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for doc-base (0.10.7) ...
Processing 2 added doc-base files...
Processing triggers for install-info (6.1.0.dfsg.1-5) ...
Setting up libgssrpc4:amd64 (1.13.2+dfsg-5) ...
Setting up libkdb5-8:amd64 (1.13.2+dfsg-5) ...
Setting up libkadm5srv-mit9:amd64 (1.13.2+dfsg-5) ...
Setting up libkadm5clnt-mit9:amd64 (1.13.2+dfsg-5) ...
Setting up comerr-dev (2.1-1.42.13-1ubuntu1) ...
Setting up krb5-multidev (1.13.2+dfsg-5) ...
Setting up libexpat1-dev:amd64 (2.1.0-7ubuntu0.16.04.2) ...
Setting up libpq5:amd64 (9.5.4-0ubuntu0.16.04) ...
Setting up zlib1g-dev:amd64 (1:1.2.8.dfsg-2ubuntu4) ...
Setting up libssl-dev:amd64 (1.0.2g-1ubuntu4.5) ...
Setting up libpq-dev (9.5.4-0ubuntu0.16.04) ...
Setting up libpython2.7-dev:amd64 (2.7.12-1~16.04) ...
Setting up libpython-dev:amd64 (2.7.11-1) ...
Setting up libpython-all-dev:amd64 (2.7.11-1) ...
Setting up libssl-doc (1.0.2g-1ubuntu4.5) ...
Setting up python-all (2.7.11-1) ...
Setting up python2.7-dev (2.7.12-1~16.04) ...
Setting up python-dev (2.7.11-1) ...
Setting up python-all-dev (2.7.11-1) ...
Setting up python-pip-whl (8.1.1-2ubuntu0.2) ...
Setting up python-pip (8.1.1-2ubuntu0.2) ...
Setting up python-pkg-resources (20.7.0-1) ...
Setting up python-setuptools (20.7.0-1) ...
Setting up python-virtualenv (15.0.1+ds-3) ...
Setting up python-wheel (0.29.0-1) ...
Setting up python3-virtualenv (15.0.1+ds-3) ...
Setting up virtualenv (15.0.1+ds-3) ...
Processing triggers for libc-bin (2.23-0ubuntu4) ...
yosuke@yosuke-vm:~$ 
yosuke@yosuke-vm:~$ mkdir hellodjango && cd hellodjango
yosuke@yosuke-vm:~/hellodjango$ virtualenv venv
Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/yosuke/hellodjango/venv/bin/python2
Also creating executable in /home/yosuke/hellodjango/venv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
yosuke@yosuke-vm:~/hellodjango$ ls -l
total 4
drwxrwxr-x 7 yosuke yosuke 4096 11月  2 11:33 venv
yosuke@yosuke-vm:~/hellodjango$ source venv/bin/activate
(venv) yosuke@yosuke-vm:~/hellodjango$ pip install django-toolbelt
Collecting django-toolbelt
  Downloading django-toolbelt-0.0.1.tar.gz
Collecting django (from django-toolbelt)
  Downloading Django-1.10.3-py2.py3-none-any.whl (6.8MB)
    100% |████████████████████████████████| 6.8MB 67kB/s 
Collecting psycopg2 (from django-toolbelt)
  Downloading psycopg2-2.6.2.tar.gz (376kB)
    100% |████████████████████████████████| 378kB 537kB/s 
Collecting gunicorn (from django-toolbelt)
  Downloading gunicorn-19.6.0-py2.py3-none-any.whl (114kB)
    100% |████████████████████████████████| 122kB 1.3MB/s 
Collecting dj-database-url (from django-toolbelt)
  Downloading dj-database-url-0.4.1.tar.gz
Collecting dj-static (from django-toolbelt)
  Downloading dj-static-0.0.6.tar.gz
Collecting static3 (from dj-static->django-toolbelt)
  Downloading static3-0.7.0.tar.gz
Building wheels for collected packages: django-toolbelt, psycopg2, dj-database-url, dj-static, static3
  Running setup.py bdist_wheel for django-toolbelt ... done
  Stored in directory: /home/yosuke/.cache/pip/wheels/28/50/35/d9bfc969dc1266fd9c38cd57472e67626b968e5e469780af0a
  Running setup.py bdist_wheel for psycopg2 ... done
  Stored in directory: /home/yosuke/.cache/pip/wheels/49/47/2a/5c3f874990ce267228c2dfe7a0589f3b0651aa590e329ad382
  Running setup.py bdist_wheel for dj-database-url ... done
  Stored in directory: /home/yosuke/.cache/pip/wheels/a6/ee/0b/fa5aa1269e9e877fc925294ecd7752e9265f42ee18d38c37dd
  Running setup.py bdist_wheel for dj-static ... done
  Stored in directory: /home/yosuke/.cache/pip/wheels/b1/84/4e/fb5706a7cfa7603abc69cc5343b4c3da7f6495f2362e7341cb
  Running setup.py bdist_wheel for static3 ... done
  Stored in directory: /home/yosuke/.cache/pip/wheels/3b/36/04/bb7140607a5fc479d180ba4eff9ed11fe141588eb24d562c60
Successfully built django-toolbelt psycopg2 dj-database-url dj-static static3
Installing collected packages: django, psycopg2, gunicorn, dj-database-url, static3, dj-static, django-toolbelt
Successfully installed dj-database-url-0.4.1 dj-static-0.0.6 django-1.10.3 django-toolbelt-0.0.1 gunicorn-19.6.0 psycopg2-2.6.2 static3-0.7.0
(venv) yosuke@yosuke-vm:~/hellodjango$ pip list
dj-database-url (0.4.1)
dj-static (0.0.6)
Django (1.10.3)
django-toolbelt (0.0.1)
gunicorn (19.6.0)
pip (8.1.2)
pkg-resources (0.0.0)
psycopg2 (2.6.2)
setuptools (28.7.1)
static3 (0.7.0)
wheel (0.30.0a0)
(venv) yosuke@yosuke-vm:~/hellodjango$ 

Djangoプロジェクトの作成

Djangoプロジェクトを作成し、gitリポジトリへ登録します。

(venv) yosuke@yosuke-vm:~/hellodjango$ django-admin.py startproject hellodjango .
(venv) yosuke@yosuke-vm:~/hellodjango$ ls -l
total 12
drwxrwxr-x 2 yosuke yosuke 4096 11月  2 11:34 hellodjango
-rwxrwxr-x 1 yosuke yosuke  809 11月  2 11:34 manage.py
drwxrwxr-x 7 yosuke yosuke 4096 11月  2 11:33 venv
(venv) yosuke@yosuke-vm:~/hellodjango$ echo 'web: gunicorn hellodjango.wsgi --log-file -' | tee Procfile
web: gunicorn hellodjango.wsgi --log-file -
(venv) yosuke@yosuke-vm:~/hellodjango$ 

foreman startでローカルサーバを起動しようとしたら、foremanが無いといわれてしまいました。
これはgemでインストールできました。

(venv) yosuke@yosuke-vm:~/hellodjango$ foreman start
The program 'foreman' is currently not installed. You can install it by typing:
sudo apt install ruby-foreman
(venv) yosuke@yosuke-vm:~/hellodjango$ gem install foreman
Fetching: thor-0.19.1.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /var/lib/gems/2.3.0 directory.
(venv) yosuke@yosuke-vm:~/hellodjango$ sudo gem install foreman
[sudo] password for yosuke: 
Fetching: thor-0.19.1.gem (100%)
Successfully installed thor-0.19.1
Fetching: foreman-0.82.0.gem (100%)
Successfully installed foreman-0.82.0
Parsing documentation for thor-0.19.1
Installing ri documentation for thor-0.19.1
Parsing documentation for foreman-0.82.0
Installing ri documentation for foreman-0.82.0
Done installing documentation for thor, foreman after 1 seconds
2 gems installed
(venv) yosuke@yosuke-vm:~/hellodjango$ 

今度こそ、ローカルサーバを実行します。
起動したら、localhost:5000をWebブラウザで開き、動作しているかを確認します。

f:id:yosuke_kirihata:20161106225518p:plain

(venv) yosuke@yosuke-vm:~/hellodjango$ foreman start
11:47:45 web.1  | started with pid 24188
11:47:46 web.1  | [2016-11-02 11:47:46 +0000] [24188] [INFO] Starting gunicorn 19.6.0
11:47:46 web.1  | [2016-11-02 11:47:46 +0000] [24188] [INFO] Listening at: http://0.0.0.0:5000 (24188)
11:47:46 web.1  | [2016-11-02 11:47:46 +0000] [24188] [INFO] Using worker: sync
11:47:46 web.1  | [2016-11-02 11:47:46 +0000] [24194] [INFO] Booting worker with pid: 24194
11:48:18 web.1  | Not Found: /favicon.ico
11:48:18 web.1  | Not Found: /favicon.ico
^Z
[1]+  Stopped                 foreman start
(venv) yosuke@yosuke-vm:~/hellodjango$ bg
[1]+ foreman start &
(venv) yosuke@yosuke-vm:~/hellodjango$ 11:48:57 web.1  | [2016-11-02 11:48:57 +0000] [24188] [CRITICAL] WORKER TIMEOUT (pid:24194)
11:48:57 web.1  | [2016-11-02 11:48:57 +0000] [24351] [INFO] Booting worker with pid: 24351
fg
foreman start
^C11:49:18 system | SIGINT received, starting shutdown
11:49:18 web.1  | [2016-11-02 11:49:18 +0000] [24188] [INFO] Handling signal: int
11:49:18 system | sending SIGTERM to all processes
11:49:18 web.1  | [2016-11-02 02:49:18 +0000] [24351] [INFO] Worker exiting (pid: 24351)
11:49:18 web.1  | [2016-11-02 11:49:18 +0000] [24188] [INFO] Shutting down: Master
11:49:18 web.1  | exited with code 0
(venv) yosuke@yosuke-vm:~/hellodjango$ 

pip freezeコマンドで使用したライブラリを設定ファイル(requirements.txt)に出力します。

(venv) yosuke@yosuke-vm:~/hellodjango$ pip freeze > requirements.txt

gitリポジトリの設定をします(個人設定の内容は[]で記載しています)。

(venv) yosuke@yosuke-vm:~/hellodjango$ cat << EOF > .gitignore
> venv
> *.pyc
> staticfiles
> EOF
(venv) yosuke@yosuke-vm:~/hellodjango$ cat .gitignore
venv
*.pyc
staticfiles
(venv) yosuke@yosuke-vm:~/hellodjango$ git config --global user.email "[メールアドレス]"
(venv) yosuke@yosuke-vm:~/hellodjango$ git config --global user.name "[名前]"
(venv) yosuke@yosuke-vm:~/hellodjango$ git init
Initialized empty Git repository in /home/yosuke/hellodjango/.git/
(venv) yosuke@yosuke-vm:~/hellodjango$ git add .
(venv) yosuke@yosuke-vm:~/hellodjango$ git commit -m "my django app"
[master (root-commit) e073893] my django app
 8 files changed, 191 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Procfile
 create mode 100644 hellodjango/__init__.py
 create mode 100644 hellodjango/settings.py
 create mode 100644 hellodjango/urls.py
 create mode 100644 hellodjango/wsgi.py
 create mode 100755 manage.py
 create mode 100644 requirements.txt
(venv) yosuke@yosuke-vm:~/hellodjango$ 

Herokuへのgitリポジトリのpush

(venv) yosuke@yosuke-vm:~/hellodjango$ heroku create
Enter your Heroku credentials.
Email: [Herokuに登録したメールアドレス]
Password (typing will be hidden): 
Logged in as [Herokuに登録したメールアドレス]
Creating app... done, ⬢ shrouded-mesa-25264
https://shrouded-mesa-25264.herokuapp.com/ | https://git.heroku.com/shrouded-mesa-25264.git
(venv) yosuke@yosuke-vm:~/hellodjango$

ここまできたらHerokuにリポジトリをpushします。が、エラーが発生してしまいました。

(venv) yosuke@yosuke-vm:~/hellodjango$ git push heroku master
Counting objects: 11, done.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (11/11), 2.91 KiB | 0 bytes/s, done.
Total 11 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing python-2.7.12
remote:      $ pip install -r requirements.txt
remote:        Collecting dj-database-url==0.4.1 (from -r requirements.txt (line 1))
remote:          Downloading dj-database-url-0.4.1.tar.gz
remote:        Collecting dj-static==0.0.6 (from -r requirements.txt (line 2))
remote:          Downloading dj-static-0.0.6.tar.gz
remote:        Collecting Django==1.10.3 (from -r requirements.txt (line 3))
remote:          Downloading Django-1.10.3-py2.py3-none-any.whl (6.8MB)
remote:        Collecting django-toolbelt==0.0.1 (from -r requirements.txt (line 4))
remote:          Downloading django-toolbelt-0.0.1.tar.gz
remote:        Collecting gunicorn==19.6.0 (from -r requirements.txt (line 5))
remote:          Downloading gunicorn-19.6.0-py2.py3-none-any.whl (114kB)
remote:        Collecting pkg-resources==0.0.0 (from -r requirements.txt (line 6))
remote:          Could not find a version that satisfies the requirement pkg-resources==0.0.0 (from -r requirements.txt (line 6)) (from versions: )
remote:        No matching distribution found for pkg-resources==0.0.0 (from -r requirements.txt (line 6))
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !	Push rejected to shrouded-mesa-25264.
remote: 
To https://git.heroku.com/shrouded-mesa-25264.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/shrouded-mesa-25264.git'
(venv) yosuke@yosuke-vm:~/hellodjango$ 

エラー内容から原因を推察し、requirements.txtのpkg-resources==0.0.0を削除しました。
commit後もう一度pushします。

(venv) yosuke@yosuke-vm:~/hellodjango$ gedit requirements.txt 
(venv) yosuke@yosuke-vm:~/hellodjango$ git status 
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   requirements.txt

no changes added to commit (use "git add" and/or "git commit -a")
(venv) yosuke@yosuke-vm:~/hellodjango$ git add requirements.txt 
(venv) yosuke@yosuke-vm:~/hellodjango$ git status 
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   requirements.txt

(venv) yosuke@yosuke-vm:~/hellodjango$ git commit -m "Edit requirements.txt"
[master 1e53405] Edit requirements.txt
 1 file changed, 1 deletion(-)
(venv) yosuke@yosuke-vm:~/hellodjango$ git push heroku master

Counting objects: 14, done.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (14/14), 3.13 KiB | 0 bytes/s, done.
Total 14 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing python-2.7.12
remote:      $ pip install -r requirements.txt
remote:        Collecting dj-database-url==0.4.1 (from -r requirements.txt (line 1))
remote:          Downloading dj-database-url-0.4.1.tar.gz
remote:        Collecting dj-static==0.0.6 (from -r requirements.txt (line 2))
remote:          Downloading dj-static-0.0.6.tar.gz
remote:        Collecting Django==1.10.3 (from -r requirements.txt (line 3))
remote:          Downloading Django-1.10.3-py2.py3-none-any.whl (6.8MB)
remote:        Collecting django-toolbelt==0.0.1 (from -r requirements.txt (line 4))
remote:          Downloading django-toolbelt-0.0.1.tar.gz
remote:        Collecting gunicorn==19.6.0 (from -r requirements.txt (line 5))
remote:          Downloading gunicorn-19.6.0-py2.py3-none-any.whl (114kB)
remote:        Collecting psycopg2==2.6.2 (from -r requirements.txt (line 6))
remote:          Downloading psycopg2-2.6.2.tar.gz (376kB)
remote:        Collecting static3==0.7.0 (from -r requirements.txt (line 7))
remote:          Downloading static3-0.7.0.tar.gz
remote:        Installing collected packages: dj-database-url, static3, dj-static, Django, psycopg2, gunicorn, django-toolbelt
remote:          Running setup.py install for dj-database-url: started
remote:            Running setup.py install for dj-database-url: finished with status 'done'
remote:          Running setup.py install for static3: started
remote:            Running setup.py install for static3: finished with status 'done'
remote:          Running setup.py install for dj-static: started
remote:            Running setup.py install for dj-static: finished with status 'done'
remote:          Running setup.py install for psycopg2: started
remote:            Running setup.py install for psycopg2: finished with status 'done'
remote:          Running setup.py install for django-toolbelt: started
remote:            Running setup.py install for django-toolbelt: finished with status 'done'
remote:        Successfully installed Django-1.10.3 dj-database-url-0.4.1 dj-static-0.0.6 django-toolbelt-0.0.1 gunicorn-19.6.0 psycopg2-2.6.2 static3-0.7.0
remote: 
remote:      $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 22, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
remote:            self.execute(*args, **cmd_options)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
remote:            output = self.handle(*args, **options)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 193, in handle
remote:            collected = self.collect()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
remote:            handler(path, prefixed_path, storage)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 337, in copy_file
remote:            if not self.delete_file(path, prefixed_path, source_storage):
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 255, in delete_file
remote:            if self.storage.exists(prefixed_path):
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py", line 394, in exists
remote:            return os.path.exists(self.path(name))
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 49, in path
remote:            raise ImproperlyConfigured("You're using the staticfiles app "
remote:        django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote: 
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote: 
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote: 
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy....
remote: 
remote: !	Push rejected to shrouded-mesa-25264.
remote: 
To https://git.heroku.com/shrouded-mesa-25264.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/shrouded-mesa-25264.git'
(venv) yosuke@yosuke-vm:~/hellodjango$ 

またもエラーが発生してしまいました…(1)
調べてみたところ、settings.pyに設定を追記とherokuに対するコマンド実行が必要のようでした。

settings.pyの末尾に下記を追記

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
)

herokuに対するコマンド実行:collectstaticって?

heroku config:set DISABLE_COLLECTSTATIC=1

設定の追記とherokuコマンドの実行を行います。

(venv) yosuke@yosuke-vm:~/hellodjango$ gedit ./hellodjango/settings.py
(venv) yosuke@yosuke-vm:~/hellodjango$ heroku config:set DISABLE_COLLECTSTATIC=1
Setting DISABLE_COLLECTSTATIC and restarting ⬢ shrouded-mesa-25264... done, v3
DISABLE_COLLECTSTATIC: 1
(venv) yosuke@yosuke-vm:~/hellodjango$ git status 
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   hellodjango/settings.py

no changes added to commit (use "git add" and/or "git commit -a")
(venv) yosuke@yosuke-vm:~/hellodjango$ git add ./hellodjango/settings.py
(venv) yosuke@yosuke-vm:~/hellodjango$ git commit -m "Edit settings.py"
[master a7246ab] Edit settings.py
 1 file changed, 9 insertions(+)
(venv) yosuke@yosuke-vm:~/hellodjango$ git push heroku masterCounting objects: 18, done.
Compressing objects: 100% (15/15), done.
Writing objects: 100% (18/18), 3.44 KiB | 0 bytes/s, done.
Total 18 (delta 5), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Installing python-2.7.12
remote:      $ pip install -r requirements.txt
remote:        Collecting dj-database-url==0.4.1 (from -r requirements.txt (line 1))
remote:          Downloading dj-database-url-0.4.1.tar.gz
remote:        Collecting dj-static==0.0.6 (from -r requirements.txt (line 2))
remote:          Downloading dj-static-0.0.6.tar.gz
remote:        Collecting Django==1.10.3 (from -r requirements.txt (line 3))
remote:          Downloading Django-1.10.3-py2.py3-none-any.whl (6.8MB)
remote:        Collecting django-toolbelt==0.0.1 (from -r requirements.txt (line 4))
remote:          Downloading django-toolbelt-0.0.1.tar.gz
remote:        Collecting gunicorn==19.6.0 (from -r requirements.txt (line 5))
remote:          Downloading gunicorn-19.6.0-py2.py3-none-any.whl (114kB)
remote:        Collecting psycopg2==2.6.2 (from -r requirements.txt (line 6))
remote:          Downloading psycopg2-2.6.2.tar.gz (376kB)
remote:        Collecting static3==0.7.0 (from -r requirements.txt (line 7))
remote:          Downloading static3-0.7.0.tar.gz
remote:        Installing collected packages: dj-database-url, static3, dj-static, Django, psycopg2, gunicorn, django-toolbelt
remote:          Running setup.py install for dj-database-url: started
remote:            Running setup.py install for dj-database-url: finished with status 'done'
remote:          Running setup.py install for static3: started
remote:            Running setup.py install for static3: finished with status 'done'
remote:          Running setup.py install for dj-static: started
remote:            Running setup.py install for dj-static: finished with status 'done'
remote:          Running setup.py install for psycopg2: started
remote:            Running setup.py install for psycopg2: finished with status 'done'
remote:          Running setup.py install for django-toolbelt: started
remote:            Running setup.py install for django-toolbelt: finished with status 'done'
remote:        Successfully installed Django-1.10.3 dj-database-url-0.4.1 dj-static-0.0.6 django-toolbelt-0.0.1 gunicorn-19.6.0 psycopg2-2.6.2 static3-0.7.0
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 41.9M
remote: -----> Launching...
remote:        Released v5
remote:        https://shrouded-mesa-25264.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/shrouded-mesa-25264.git
 * [new branch]      master -> master
(venv) yosuke@yosuke-vm:~/hellodjango$ 

無事pushに成功しました!

下記のコマンドでWebブラウザを起動し、アプリのページを開くことができます。

(venv) yosuke@yosuke-vm:~/hellodjango$ heroku open
(venv) yosuke@yosuke-vm:~/hellodjango$ 

しかし、ページを表示してみるとエラーが発生しています…(2)

f:id:yosuke_kirihata:20161106225436p:plain


調べると、settings.pyに設定が足らなかったようです。

# Allow all host headers
ALLOWED_HOSTS = ['*']

よくわかっていませんが、追記します。

(venv) yosuke@yosuke-vm:~/hellodjango$ gedit ./hellodjango/settings.py(venv) yosuke@yosuke-vm:~/hellodjango$ git add ./hellodjango/settings.py
(venv) yosuke@yosuke-vm:~/hellodjango$ git commit -m "Edit settings.py"
[master 9aca805] Edit settings.py
 1 file changed, 5 insertions(+)
(venv) yosuke@yosuke-vm:~/hellodjango$ git push heroku master
Counting objects: 4, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 437 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote:      $ pip install -r requirements.txt
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 41.9M
remote: -----> Launching...
remote:        Released v6
remote:        https://shrouded-mesa-25264.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/shrouded-mesa-25264.git
   a7246ab..9aca805  master -> master
(venv) yosuke@yosuke-vm:~/hellodjango$ 

リポジトリのpush成功後、再度アプリのページを表示します。

TODO:後で実行できたページの画像を張る!!

これで完了です!!

さいごに

HerokuにDjangoアプリをデプロイすることができました。
色々わかっていない箇所も多いのですが、ひとまず動作させることができたので、良しとします。

参考Webページ

参考元の導入手順
Ubuntu 14.04 で Django アプリケーションを Heroku にデプロイする手順 | dreamin'up4u

foremanのインストール他
foreman で アプリケーションを動かす。 - Qiita

エラー(1)対処:settings.pyに追記した内容
PROJECT_ROOT/STATIC_ROOT/STATIC_URL/STATICFILES_DIRSの項目を追記
herokuへのDISABLE_COLLECTSTATIC=1設定
Django製apiをherokuでデプロイする(自分用メモ) - Qiita

エラー(2)対処:さらにsettings.pyに追記した内容
ALLOWED_HOSTS = ['*']を追記
python - Is ALLOWED_HOSTS needed on Heroku? - Stack Overflow

Heroku Tips
Heroku Command Line | Heroku Dev Center

herokuのログをリアルタイムでみる - Qiita

Heroku CLI 簡単リファレンス - Qiita