1
pip install python-dotenv
django에서 사용하는 예시
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# settings.py
from django.core.exceptions import ImproperlyConfigured
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
def get_env_value(env_variable: str):
try:
return os.environ[env_variable]
except KeyError:
raise ImproperlyConfigured()
SECRET_KEY = get_env_value("SECRET_KEY")
1
2
# .env
SECRET_KEY = "THISISSECRETKEY"
1
2
# .gitignore
.env