From 1dc1310b9f93a076d088a57333322af9c929d40d Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Tue, 17 Sep 2024 17:37:36 +0200 Subject: [PATCH] Use environs to get settings --- django_cats/settings.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/django_cats/settings.py b/django_cats/settings.py index e90d225..7af084d 100644 --- a/django_cats/settings.py +++ b/django_cats/settings.py @@ -11,23 +11,30 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ """ from pathlib import Path +from environs import Env # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent +env = Env() +env.read_env() + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = env.bool("DEBUG", default=False) + +# SECURITY WARNING: keep the secret key used in production secret! +if DEBUG: + SECRET_KEY = env.str("SECRET_KEY", + default="django-insecure-m8s=a8rg)_cqo%q$g8qzzho&160+jei4uocg%q-ce3v_kfumr7") +else: + SECRET_KEY = env.str("SECRET_KEY") + # Quick-start development settings - unsuitable for production # 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-m8s=a8rg)_cqo%q$g8qzzho&160+jei4uocg%q-ce3v_kfumr7" - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - ALLOWED_HOSTS = [] - # Application definition INSTALLED_APPS = [ @@ -73,12 +80,7 @@ WSGI_APPLICATION = "django_cats.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", - } -} +DATABASES = {"default": env.dj_db_url("DATABASE_URL")} # Password validation