X-Git-Url: https://code.kerkeslager.com/?a=blobdiff_plain;f=styx%2Fsettings.py;h=acfb6313571474a07ba71c46d552612fe7b530e8;hb=b229eb5f8c93cd51bf867c6e1c17e832b8015ce9;hp=0f2aca0d023c022bb35fb7e1d62ebd8350c41f19;hpb=ffe1dbea37b51e0ccc9075e834f849474da49d7b;p=styx.blog diff --git a/styx/settings.py b/styx/settings.py index 0f2aca0..acfb631 100644 --- a/styx/settings.py +++ b/styx/settings.py @@ -11,6 +11,8 @@ https://docs.djangoproject.com/en/3.1/ref/settings/ """ from pathlib import Path +import json +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve(strict=True).parent.parent @@ -19,14 +21,27 @@ BASE_DIR = Path(__file__).resolve(strict=True).parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'mq@_9a6&y4nvgqa7obf-r%a4^dt)z=r8jr&91&=oc^6-=i0*$z' +try: + with open(os.path.expanduser('~/.styxrc'), 'r') as styxrc: + LOCAL_SETTINGS = json.loads(styxrc.read()) -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] +except FileNotFoundError: + LOCAL_SETTINGS = {} +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = LOCAL_SETTINGS.get('DEBUG', True) + +if DEBUG: + SECRET_KEY = 'mq@_9a6&y4nvgqa7obf-r%a4^dt)z=r8jr&91&=oc^6-=i0*$z' +else: + SECRET_KEY = LOCAL_SETTINGS['SECRET_KEY'] + +ALLOWED_HOSTS = [ + 'localhost', + 'www.localhost', + 'styx.blog', + '46.101.172.187', +] # Application definition @@ -73,12 +88,22 @@ WSGI_APPLICATION = 'styx.wsgi.application' # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', +if DEBUG: + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } + } +else: + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'styx', + 'USER': 'styxuser', + 'PASSWORD': LOCAL_SETTINGS['DB_PASSWORD'], + } } -} # Password validation @@ -118,3 +143,4 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static/')