How to access Django secret key when git cloning from github?
So I have placed Django secret key in base.json and added that in .gitignore to prevent push and pulls to github and edited settings.py accordingly as such.
Problem is that I am trying to deploy my api to AWS ec2 and when I git clone on my Ubuntu terminal, obviously that base.json file is missing and I cannot run my code because secret key is not found. So what should I do in this case?
settings.py:
import os, json
from django.core.exceptions import ImproperlyConfigured
secret_file = os.path.join(BASE_DIR, 'base.json')
with open(secret_file) as f:
secrets = json.loads(f.read())
def get_secret(setting, secrets=secrets):
try:
return secrets[setting]
except KeyError:
error_msg = "Set the {} environment variable".format(setting)
raise ImproperlyConfigured(error_msg)
SECRET_KEY = get_secret("SECRET_KEY")
DEBUG = False
ALLOWED_HOSTS = ['*']
I have seen How to access Heroku config variables inside Django settings and other similar ones but they all relate to Heroku and not my case.