0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python dotenvでの環境変数設定について

Posted at

tl;dr

  • 環境変数とは、OSの動作に対して外部から与えられる変数
  • DBやAPIのKeyなど人に見せないように(githubにアップされないように)しながら使う方法

What we did?

Install

$ pip install python-dotenv
python app.py
from dotenv import load_dotenv

load_dotenv('{{file name}}')
stripe.api_key = os.environ.get("Stripe_API_KEY")
.env
Stripe_API_KEY = "sk_live_XXXXXXX"
.gitignore
.env

上記にて環境変数自体はリモートリポジトリに置いたまま、アプリケーションから参照できるようになった。

Home work

  • 上記はまだ開発環境のため、本番環境の際にどのように設定するかは調べていない
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?