From 4b77c454c372b1f4c79213c10d029647871991ee Mon Sep 17 00:00:00 2001 From: Jonathan Peacher Date: Sun, 18 Jun 2023 09:34:47 -0500 Subject: [PATCH] feat: prepped for digital ocean https://docs.digitalocean.com/tutorials/app-deploy-django-app/ --- projects/settings.py | 30 ++++++++++++++++++++---------- requirements.txt | 7 +++++++ 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 requirements.txt diff --git a/projects/settings.py b/projects/settings.py index fc45b14..0ad4061 100644 --- a/projects/settings.py +++ b/projects/settings.py @@ -9,7 +9,9 @@ https://docs.djangoproject.com/en/4.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.2/ref/settings/ """ - +import os +import sys +import dj_database_url from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -20,12 +22,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-7@idp#yf6!fvk$aky7)q3kwhh@#_stp2+7dkulmdoz=ld=xy18' +SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", 'django-insecure-7@idp#yf6!fvk$aky7)q3kwhh@#_stp2+7dkulmdoz=ld=xy18') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = os.getenv("DEBUG", "False") == "True" -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = os.getenv("DJANGO_ALLOWED_HOSTS", "127.0.0.1,localhost").split(",") # Application definition @@ -73,12 +75,19 @@ WSGI_APPLICATION = 'projects.wsgi.application' # Database # https://docs.djangoproject.com/en/4.2/ref/settings/#databases -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', +if DEBUG is True: + DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + } + } +elif len(sys.argv) > 0 and sys.argv[1] != 'collectstatic': + if os.getenv("DATABASE_URL", None) is None: + raise Exception("DATABASE_URL environment variable not defined") + DATABASES = { + "default": dj_database_url.parse(os.environ.get("DATABASE_URL")), } -} # Password validation @@ -115,7 +124,8 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ -STATIC_URL = 'static/' +STATIC_URL = "/static/" +STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") # Default primary key field type # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..57d083a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +asgiref==3.7.2 +dj-database-url==2.0.0 +Django==4.2.2 +gunicorn==20.1.0 +psycopg2-binary==2.9.6 +sqlparse==0.4.4 +typing_extensions==4.6.3