Skip to content

Commit

Permalink
separate dev and prod setting templates
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Jun 12, 2018
1 parent fb650d6 commit dd01d47
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 28 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.pyc
local_settings.py
venv
htdocs
lib
Expand Down
2 changes: 1 addition & 1 deletion db/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions db/project_name/settings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dev.py
prod.py
Empty file.
24 changes: 5 additions & 19 deletions db/project_name/settings.py → db/project_name/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
28 changes: 28 additions & 0 deletions db/project_name/settings/dev.py
Original file line number Diff line number Diff line change
@@ -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'

Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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
2 changes: 1 addition & 1 deletion db/project_name/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit dd01d47

Please sign in to comment.