LoginSignup
0
0

More than 5 years have passed since last update.

DjangoでHerokuデプロイ

Posted at

基本的にローカル環境で一通り稼働したアプリケーションをHerokuにデプロイする際の
変更点を記述する。Flaskとも異なるので

①デプロイに必要なファイルはFlaskの時と同じく(修正は必要)
・Procfile
・requirements.txt
・runtime.txt
②修正する部分は
settings.py
wsgi.py

③異なる作業は
.デプロイ後のマイグレーション


まず
whitenoiseをinstallしておく


・requirements.txtは使用しているライブラリーに加えwhitenoiseが
うまく動かないのでversion4からverison3に下げた

・ただしアプリケーションの駆動が異なる点であり、wsgi.pyに修正が必要
 かつそのためProcfile ではgunicorn wsgiにする.つまりProcfileに以下のように記述する

Procfile

 web: gunicorn myapp.wsgi

settings.py

ALLOWED_HOST=[*]

HOSTを解放しておく。

wsgi.pyは以下のようにした。

wsgi.py


import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapp.settings')

application = get_wsgi_application()

from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)

デプロイはFlaskの時と同じ

push heroku master後にDBマイグレいとが必要だが
以下のコマンドでherokuに指示する。

heroku run python manage.py makemigrations
heroku run python manage.py migrate

おかしい部分があるような気がしたが問題なくアプリケーションが起動できた。
ちなみにDBはPostgresSQLが使用され、それはAWS上のにあるとのことらしい。

ちなみにHeroku git:remote -aアプリ名 で特手にのheroku appに接続できる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0