From: Patrick Canterino <patrick@patrick-canterino.de>
Date: Sun, 23 Jan 2022 15:01:09 +0000 (+0100)
Subject: Get SECRET_KEY and DEBUG from .env
X-Git-Url: https://git.p6c8.net/pcdenotes.git/commitdiff_plain/16158647286ae7497203e084789688c613698d68?hp=d58d60efc6e8087bfdde14c83c7989799bf6a568

Get SECRET_KEY and DEBUG from .env

Also set ALLOW_HOSTS to '*'
---

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