From dd01d47b6c23a28c058105beadbab2762960de25 Mon Sep 17 00:00:00 2001 From: "S. Andrew Sheppard" Date: Tue, 12 Jun 2018 16:27:49 -0500 Subject: [PATCH] separate dev and prod setting templates --- .gitignore | 1 - db/manage.py | 2 +- db/project_name/settings/.gitignore | 2 ++ db/project_name/settings/__init__.py | 0 .../{settings.py => settings/base.py} | 24 ++++------------ db/project_name/settings/dev.py | 28 +++++++++++++++++++ .../{local_settings.py => settings/prod.py} | 24 ++++++++++++---- db/project_name/wsgi.py | 2 +- 8 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 db/project_name/settings/.gitignore create mode 100644 db/project_name/settings/__init__.py rename db/project_name/{settings.py => settings/base.py} (83%) create mode 100644 db/project_name/settings/dev.py rename db/project_name/{local_settings.py => settings/prod.py} (62%) diff --git a/.gitignore b/.gitignore index 2e78226..b08e8d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.pyc -local_settings.py venv htdocs lib diff --git a/db/manage.py b/db/manage.py index 0ab12ad..cd52a38 100755 --- a/db/manage.py +++ b/db/manage.py @@ -3,7 +3,7 @@ import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings.dev") from django.core.management import execute_from_command_line diff --git a/db/project_name/settings/.gitignore b/db/project_name/settings/.gitignore new file mode 100644 index 0000000..a2ac02f --- /dev/null +++ b/db/project_name/settings/.gitignore @@ -0,0 +1,2 @@ +dev.py +prod.py diff --git a/db/project_name/settings/__init__.py b/db/project_name/settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/db/project_name/settings.py b/db/project_name/settings/base.py similarity index 83% rename from db/project_name/settings.py rename to db/project_name/settings/base.py index 3f4eb2e..71df567 100644 --- a/db/project_name/settings.py +++ b/db/project_name/settings/base.py @@ -16,14 +16,13 @@ """ import os +from os.path import dirname # Build paths inside the project like this: os.path.join(BASE_DIR, ...) -# wq: extra dirname() to account for db/ folder -BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +# wq: extra dirname()s to account for db/ and settings/ folders +BASE_DIR = dirname(dirname(dirname(dirname(os.path.abspath(__file__))))) -# wq: SECRET_KEY and DEBUG are defined in local_settings.py - -ALLOWED_HOSTS = ["{{ domain }}"] +# wq: SECRET_KEY, DEBUG, and ALLOWED_HOSTS are defined in dev.py/prod.py # Application definition @@ -73,10 +72,7 @@ WSGI_APPLICATION = '{{ project_name }}.wsgi.application' -# Database -# https://docs.djangoproject.com/en/2.0/ref/settings/#databases - -# wq: DATABASES is defined in local_settings.py +# wq: DATABASES is defined in dev.py/prod.py # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators @@ -121,13 +117,3 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media') VERSION_TXT = os.path.join(BASE_DIR, 'version.txt') MEDIA_URL = '/media/' - -# wq: Import local settings -try: - from .local_settings import * -except ImportError: - pass - -# wq: Determine if we are running off django's testing server -import sys -DEBUG_WITH_RUNSERVER = 'manage.py' in sys.argv[0] diff --git a/db/project_name/settings/dev.py b/db/project_name/settings/dev.py new file mode 100644 index 0000000..958b81e --- /dev/null +++ b/db/project_name/settings/dev.py @@ -0,0 +1,28 @@ +import os +import sys +from .base import * + + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '{{ secret_key }}' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +# wq: Determine if we are running off django's testing server +DEBUG_WITH_RUNSERVER = 'manage.py' in sys.argv[0] + +ALLOWED_HOSTS = [] + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.contrib.gis.db.backends.spatialite', + 'NAME': os.path.join(BASE_DIR, 'conf', '{{ project_name }}.sqlite3'), + } +} + +SPATIALITE_LIBRARY_PATH = 'mod_spatialite' + diff --git a/db/project_name/local_settings.py b/db/project_name/settings/prod.py similarity index 62% rename from db/project_name/local_settings.py rename to db/project_name/settings/prod.py index 3b278f2..1419afa 100644 --- a/db/project_name/local_settings.py +++ b/db/project_name/settings/prod.py @@ -1,3 +1,21 @@ +from .base import * + + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '{{ secret_key }}' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False + +# wq: Determine if we are running off django's testing server +DEBUG_WITH_RUNSERVER = False + +ALLOWED_HOSTS = ["{{ domain }}"] + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + DATABASES = { 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', @@ -8,9 +26,3 @@ 'PORT': '', } } - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '{{ secret_key }}' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True diff --git a/db/project_name/wsgi.py b/db/project_name/wsgi.py index adc0811..7527ff9 100644 --- a/db/project_name/wsgi.py +++ b/db/project_name/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings.prod") application = get_wsgi_application()