2
1

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 3 years have passed since last update.

Django local_settings.pyに書いた公開したくない情報をsettings.pyに導入する方法

Posted at

#local.settings.pyの設定
まずsettings.pyのファイルがある同じ階層にlocal_settings.py(名前はなんでも良い)、.gitignoreを作成します。.gitignoreにlocal_settings.pyを追加します。

次にlocal_settings.pyに公開したくない情報を以下のように書きます。

local_settings.py
SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

DATABASES = {
    'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
}

#settings.pyの設定
settings.pyに以下のコードを追加します

settings.py
try:
    from .local_settings import *
except ImportError:
    pass

以上です。
これでGithubなどで公開したくない情報をlocal_settings.pyに書いて、settings.pyに導入することができます。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?