From fbdfa32765009cce1ada4e1577abf4c58d9bb5d9 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 21 Oct 2021 14:29:10 +0100 Subject: [PATCH] load local_settings --- .gitignore | 2 ++ app/settings.py | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 474786d..85dbdb3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ www/ *.swp venv *.swo +secret.txt +app/local_settings.py diff --git a/app/settings.py b/app/settings.py index 8fe4332..14cebcb 100644 --- a/app/settings.py +++ b/app/settings.py @@ -19,9 +19,6 @@ BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # 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-4^*01ba-twojkikte8_7q_%zc96f@i%^gwg-36*xlr1&l4w-im' - # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -148,3 +145,26 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' TIMELINE_PREFIX = "https://aab21.pad.ma/" URL_PREFIX = 'polis+' + +try: + from local_settings import * +except ImportError: + pass + +# Make this unique, creates random key first at first time. +try: + SECRET_KEY +except NameError: + SECRET_FILE = BASE_DIR / 'secret.txt' + try: + SECRET_KEY = open(SECRET_FILE).read().strip() + except IOError: + try: + from django.utils.crypto import get_random_string + chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' + SECRET_KEY = get_random_string(50, chars) + secret = open(SECRET_FILE, 'w') + secret.write(SECRET_KEY) + secret.close() + except IOError: + raise Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE)