From d727afe5b83efa5cc54b0140205ca2666daea892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Thu, 14 Nov 2024 12:38:00 +0100 Subject: [PATCH] Add decouple + config Use python-decouple Config method to load the config values (debug, database, secret_key...) more to come --- env.sample | 1 + src/blueskydj/blueskydj/settings.py | 13 +++++++++---- src/requirements.txt | 3 +-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/env.sample b/env.sample index 098ab25..2e8ffba 100644 --- a/env.sample +++ b/env.sample @@ -12,4 +12,5 @@ MYSQL_PASSWORD=pass MYSQL_ROOT_PASSWORD=pass DEBUG=True +SECRET_KEY=django-secret-key-123123-abcabc DJANGO_SETTINGS_MODULE=project.settings.devel diff --git a/src/blueskydj/blueskydj/settings.py b/src/blueskydj/blueskydj/settings.py index 9409775..59c2ec7 100644 --- a/src/blueskydj/blueskydj/settings.py +++ b/src/blueskydj/blueskydj/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/5.1/ref/settings/ """ from pathlib import Path +from decouple import config # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -20,10 +21,10 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-h#0))ubik6g6_azpi-0tf)=y%@m&488#2io&(5x+k^)10ns_41' +SECRET_KEY = config('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = config('DEBUG', default=False, cast=bool) ALLOWED_HOSTS = [] @@ -75,8 +76,12 @@ WSGI_APPLICATION = 'blueskydj.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + 'ENGINE': 'django.db.backends.mysql', + 'NAME': config('MYSQL_DATABASE'), + 'USER': config('MYSQL_USER'), + 'PASSWORD': config('MYSQL_PASSWORD'), + 'HOST': config('MYSQL_HOST'), + 'PORT': config('MYSQL_PORT'), } } diff --git a/src/requirements.txt b/src/requirements.txt index e2ae4cc..dbde922 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,3 +1,2 @@ -asgiref==3.8.1 Django==5.1.3 -sqlparse==0.5.2 +python-decouple==3.8