feat: add support for loading environment variables from a .env file in settings
Some checks failed
Deploy Beta (NATIVE) / deploy (push) Failing after 19s
Some checks failed
Deploy Beta (NATIVE) / deploy (push) Failing after 19s
This commit is contained in:
parent
73db3576bf
commit
3002ce14c6
1 changed files with 10 additions and 0 deletions
|
|
@ -17,6 +17,16 @@ from pathlib import Path
|
|||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
# Load environment variables from .env file if it exists
|
||||
env_path = BASE_DIR / '.env'
|
||||
if env_path.exists():
|
||||
with open(env_path) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#') and '=' in line:
|
||||
k, v = line.split('=', 1)
|
||||
os.environ.setdefault(k.strip(), v.strip())
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/6.1/howto/deployment/checklist/
|
||||
|
|
|
|||
Loading…
Reference in a new issue