LoginSignup
0
2

More than 5 years have passed since last update.

PythonのWebアプリをHerokuで動かすときの設定情報の読み替え方法

Posted at

Python+FlaskのWebアプリをHerokuで動かすとき設定情報をローカル環境とHeroku環境でどう読み替えさせるか悩んだのでやった方法を残します。

Herokuの環境変数を設定
ローカルには「settings.py」とかでファイルをつくりそこにキー情報を格納
.gitignoreにsettings.pyを追加
下記のように設定情報を取得

import os


if os.getenv('SOME_KEY') is not None:
    SOME_KEY = os.environ.get('SOME_KEY')
else:
    import settings
    SOME_KEY = settings.SOME_KEY

これでGitHubにキー情報をあげないでローカルでもherokuでも読み替えられるようになった。

Python3.6

0
2
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
2