From 9fd3d6e431a40facf2c69ba6c5ed8ceba064ec43 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 7 Nov 2018 13:47:23 +0100 Subject: [PATCH] settings --- .idea/inspectionProfiles/Project_Default.xml | 14 +++++++++++ recipes/secret_settings.template | 25 ------------------- recipes/{settings.py => settings.py.template} | 25 ++++++++++++++++--- requirements.txt | 5 +++- 4 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 recipes/secret_settings.template rename recipes/{settings.py => settings.py.template} (82%) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..97166f165 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/recipes/secret_settings.template b/recipes/secret_settings.template deleted file mode 100644 index 5fd8378f9..000000000 --- a/recipes/secret_settings.template +++ /dev/null @@ -1,25 +0,0 @@ -""" -Setting file for secret settings -imported by settings.py - -TEMPLATE FILE: remove .template extension and fill in missing values -""" - -import os - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -# defined in secret settings to be able to use local sqlite db's -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '' - -# Database -# https://docs.djangoproject.com/en/2.0/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} diff --git a/recipes/settings.py b/recipes/settings.py.template similarity index 82% rename from recipes/settings.py rename to recipes/settings.py.template index 2ae2ae644..aa71d7ba8 100644 --- a/recipes/settings.py +++ b/recipes/settings.py.template @@ -9,17 +9,22 @@ https://docs.djangoproject.com/en/2.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.0/ref/settings/ """ +import os from django.contrib import messages from recipes.secret_settings import * +from dotenv import load_dotenv + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +# Get vars from .env files +SECRET_KEY = os.getenv('SECRET_KEY') -ALLOWED_HOSTS = ['192.168.178.27', '127.0.0.1'] +DEBUG = bool(int(os.getenv('DEBUG', False))) + +ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS').split(',') if os.getenv('ALLOWED_HOSTS') else [] LOGIN_REDIRECT_URL = "index" LOGOUT_REDIRECT_URL = "index" @@ -79,6 +84,20 @@ TEMPLATES = [ WSGI_APPLICATION = 'recipes.wsgi.application' +# Database +# Load settings from env files + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'HOST': os.getenv('POSTGRES_HOST'), + 'PORT': os.getenv('POSTGRES_PORT'), + 'USER': os.getenv('POSTGRES_USER'), + 'PASSWORD': os.getenv('POSTGRES_PASSWORD'), + 'NAME': os.getenv('POSTGRES_DB'), + } +} + # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators diff --git a/requirements.txt b/requirements.txt index 9af8c3106..249224b43 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,7 @@ django-tables2 django-filter django-crispy-forms djangorestframework -django-autocomplete-light \ No newline at end of file +django-autocomplete-light +python-dotenv==0.7.1 +psycopg2==2.7.4 +gunicorn==19.7.1 \ No newline at end of file