Add decouple + config

Use python-decouple Config method to load the config values
(debug, database, secret_key...) more to come
This commit is contained in:
Óscar M. Lage 2024-11-14 12:38:00 +01:00
parent a50b457585
commit d727afe5b8
3 changed files with 11 additions and 6 deletions

View File

@ -12,4 +12,5 @@ MYSQL_PASSWORD=pass
MYSQL_ROOT_PASSWORD=pass MYSQL_ROOT_PASSWORD=pass
DEBUG=True DEBUG=True
SECRET_KEY=django-secret-key-123123-abcabc
DJANGO_SETTINGS_MODULE=project.settings.devel DJANGO_SETTINGS_MODULE=project.settings.devel

View File

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/5.1/ref/settings/
""" """
from pathlib import Path from pathlib import Path
from decouple import config
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent 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/ # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # 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! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = config('DEBUG', default=False, cast=bool)
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
@ -75,8 +76,12 @@ WSGI_APPLICATION = 'blueskydj.wsgi.application'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.mysql',
'NAME': BASE_DIR / 'db.sqlite3', 'NAME': config('MYSQL_DATABASE'),
'USER': config('MYSQL_USER'),
'PASSWORD': config('MYSQL_PASSWORD'),
'HOST': config('MYSQL_HOST'),
'PORT': config('MYSQL_PORT'),
} }
} }

View File

@ -1,3 +1,2 @@
asgiref==3.8.1
Django==5.1.3 Django==5.1.3
sqlparse==0.5.2 python-decouple==3.8