Skip to content

Commit

Permalink
separate settings for prod and dev
Browse files Browse the repository at this point in the history
  • Loading branch information
arminpatel committed Jan 26, 2024
1 parent 49a86a4 commit a0f8ca2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
13 changes: 1 addition & 12 deletions backend/core/settings.py → backend/core/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from pathlib import Path
from dotenv import load_dotenv
import dj_database_url

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -17,7 +16,7 @@
STRIPE_WEBHOOK_SECRET = os.environ.get('STRIPE_WEBHOOK_SECRET', 'default')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DJANGO_DEBUG', "False").lower == 'true'
DEBUG = os.environ.get('DEBUG') != 'False'

ALLOWED_HOSTS = ['*']
# ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS').split(' ')
Expand Down Expand Up @@ -97,16 +96,6 @@
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
# dj_database_url.config(default=os.environ.get('DATABASE_URL'))
# dj_database_url.parse(os.environ.get("DATABASE_URL"))
}
}

DATABASES['default'] = dj_database_url.parse(os.environ.get("DATABASE_URL"))
# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

Expand Down
10 changes: 10 additions & 0 deletions backend/core/settings/development.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .base import * # noqa: F403, F401

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
# dj_database_url.config(default=os.environ.get('DATABASE_URL'))
# dj_database_url.parse(os.environ.get("DATABASE_URL"))
}
}
8 changes: 8 additions & 0 deletions backend/core/settings/production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

from .base import * # noqa: F403, F401
import dj_database_url

DATABASES = {
'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'))
}
7 changes: 6 additions & 1 deletion backend/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
import os
import sys

from core.settings import base


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
if base.DEBUG:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings.development')
else:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings.production')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down

0 comments on commit a0f8ca2

Please sign in to comment.