From 16158647286ae7497203e084789688c613698d68 Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Sun, 23 Jan 2022 16:01:09 +0100 Subject: [PATCH] Get SECRET_KEY and DEBUG from .env Also set ALLOW_HOSTS to '*' --- .gitignore | 1 + pcdenotes/settings.py | 11 ++++++++--- requirements.txt | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 646c513..fcc7e9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.env .venv __pycache__ db.sqlite3 diff --git a/pcdenotes/settings.py b/pcdenotes/settings.py index 3ec7465..fdd29e4 100644 --- a/pcdenotes/settings.py +++ b/pcdenotes/settings.py @@ -12,6 +12,11 @@ https://docs.djangoproject.com/en/3.2/ref/settings/ from pathlib import Path +from dotenv import load_dotenv, find_dotenv +load_dotenv(find_dotenv()) + +import os + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -20,12 +25,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-(bf$#80p=*wkj(yh$)3oec0nn#46k$8(m#hx4yx8d02kcog3$q' +SECRET_KEY = str(os.getenv('PCDENOTES_SECRET_KEY')) # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = str(os.getenv('PCDENOTES_DEBUG', 'false')).lower() == 'true' -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['*'] # Application definition diff --git a/requirements.txt b/requirements.txt index cdc394b..ff18f3b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ Markdown==3.3.6 packaging==21.3 pkg-resources==0.0.0 pyparsing==3.0.6 +python-dotenv==0.19.2 pytz==2021.3 six==1.16.0 sqlparse==0.4.2 -- 2.34.1