diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f8f7abc --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +DB_NAME= +DB_USER= +DB_PASSWORD= +DB_HOST= +DB_PORT= \ No newline at end of file diff --git a/eventyog/settings.py b/eventyog/settings.py index 06aee7a..026c68b 100644 --- a/eventyog/settings.py +++ b/eventyog/settings.py @@ -12,6 +12,7 @@ from pathlib import Path import os +from dotenv import load_dotenv # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -79,8 +80,25 @@ # Database # https://docs.djangoproject.com/en/5.1/ref/settings/#databases +# Add these at the top of your settings.py -DATABASES = { + +load_dotenv() # Load environment variables from a .env file + +if PRODUCTION: + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': os.getenv('DB_NAME', 'eventyog'), + 'USER': os.getenv('DB_USER', 'pemilos24_owner'), + 'PASSWORD': os.getenv('DB_PASSWORD', 'DRzSsw7Pc2HE'), + 'HOST': os.getenv('DB_HOST', 'ep-late-cloud-a1j1feg2-pooler.ap-southeast-1.aws.neon.tech'), + 'PORT': os.getenv('DB_PORT', 5432), + } +} + +else: + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', diff --git a/requirements.txt b/requirements.txt index c458349..6e9448e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ gunicorn whitenoise psycopg2-binary requests -urllib3 \ No newline at end of file +urllib3 +python-dotenv \ No newline at end of file