Keep Secret Keys Out

前端 未结 7 794
情话喂你
情话喂你 2020-12-07 21:02

One of the causes of the local_settings.py anti-pattern is that putting SECRET_KEY, AWS keys, etc.. values into settings files has problem:

  • Secrets often shoul
相关标签:
7条回答
  • 2020-12-07 21:53

    Here's one way to do it that is compatible with deployment on Heroku:

    1. Create a gitignored file named .env containing:

      export DJANGO_SECRET_KEY = 'replace-this-with-the-secret-key'

    2. Then edit settings.py to remove the actual SECRET_KEY and add this instead:

      SECRET_KEY = os.environ['DJANGO_SECRET_KEY']

    3. Then when you want to run the development server locally, use:

      source .env
      python manage.py runserver

    4. When you finally deploy to Heroku, go to your app Settings tab and add DJANGO_SECRET_KEY to the Config Vars.

    0 讨论(0)
提交回复
热议问题