diff --git a/.gitignore b/.gitignore index 12e92ae8f7d4e25abdbfb790213192cce6b52fa5..f9b6220d0369fd02aedf869fa9863ed44fd57b3c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ docs/_build # Ignore local tmp directory. tmp/ + +# Ignore the file with credentials. +credentials.py \ No newline at end of file diff --git a/project/project_name/settings/__init__.py b/project/project_name/settings/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..5312dcceb024abe979fcc487bb8e18e7ab08746e --- /dev/null +++ b/project/project_name/settings/__init__.py @@ -0,0 +1,2 @@ +# Run the development site by default. +from .development import * diff --git a/project/project_name/settings.py b/project/project_name/settings/base.py similarity index 50% rename from project/project_name/settings.py rename to project/project_name/settings/base.py index 87cc7136cd8f81768dfef65d5e4d0030d770c673..5025e2fbbcc2906e469fc00139706f637836b712 100644 --- a/project/project_name/settings.py +++ b/project/project_name/settings/base.py @@ -1,35 +1,17 @@ -""" -Django settings for {{ project_name }} project. +# Common Django settings for all environments for project {{ project_name }}. -Generated by 'django-admin startproject' using Django {{ django_version }}. +# +# This file contains common settings shared amongst all environments of a +# project. Do not put any environment-specific settings here. +# -For more information on this file, see -https://docs.djangoproject.com/en/{{ docs_version }}/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/ -""" - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/checklist/ - -# 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 - -ALLOWED_HOSTS = [] - - -# Application definition +# Determine the root and assets project directories. +PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +ASSETS_ROOT = os.path.normpath(os.path.join(PROJECT_ROOT, "assets")) +# Applications installed in the project. INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', @@ -39,6 +21,7 @@ INSTALLED_APPS = ( 'django.contrib.staticfiles', ) +# Middleware classes enabled in the project. MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -50,8 +33,10 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.security.SecurityMiddleware', ) +# URL configuration for the project. ROOT_URLCONF = '{{ project_name }}.urls' +# Templates configuration for the project. TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -68,35 +53,29 @@ TEMPLATES = [ }, ] +# Python dotted path to the WSGI application used by Django's runserver command. WSGI_APPLICATION = '{{ project_name }}.wsgi.application' - -# Database -# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - - -# Internationalization -# https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/ - +# Language, internationalisation, and time configuration LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - USE_I18N = True - USE_L10N = True - USE_TZ = True +# URLs for serving the static and media files. +STATIC_URL = '/static/' +MEDIA_URL = '/media/' -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/ +# Absolute filesystem path to the directory that will hold user-uploaded +# files. Calculated based on assets root. +MEDIA_ROOT = os.path.normpath(os.path.join(ASSETS_ROOT, "media")) -STATIC_URL = '/static/' +# Absolute path to the directory static files should be collected to. Calculated +# based on project assets root. +STATIC_ROOT = os.path.normpath(os.path.join(ASSETS_ROOT, "static")) + +# Additional locations for static files. Useful for project-wide overrides of +# default static files. +STATICFILES_DIRS = ( + os.path.normpath(os.path.join(PROJECT_ROOT, "static")), +) diff --git a/project/project_name/settings/development.py b/project/project_name/settings/development.py new file mode 100644 index 0000000000000000000000000000000000000000..ff665a8a1dc2d39c50319e9ec9fb8ba68e698f81 --- /dev/null +++ b/project/project_name/settings/development.py @@ -0,0 +1,52 @@ +# Development environment settings for project {{ project_name }}. + +# +# This configuration file is used to define settings for the development +# environment. +# + +# Import the exception for signaling invalid configuration. No other +# Django-specific definitions should be imported here. +from django.core.exceptions import ImproperlyConfigured + +# Import the base settings. +from .base import * + +# Import the credentials. +try: + from .credentials import DATABASE_PASSWORDS +except ImportError: + raise ImproperlyConfigured("Please configure the DATABASE_PASSWORDS in credentials.py.") + +try: + from .credentials import SECRET_KEY +except ImportError: + raise ImproperlyConfigured("Please configure the SECRET_KEY in credentials.py.") + +# Debugging is useful for development. +DEBUG = True +for template_config in TEMPLATES: + template_config['OPTIONS']['debug']=True + +# Site administrators and managers. +ADMINS = ( + # ('Your Name', 'your_email@example.com'), +) +MANAGERS = ADMINS + +# Database configuration. sqlite3 is used for development for convenience. See +# testing/production environment settings and official Django documentation if a +# proper database should be used. +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': 'development.sqlite3', + } +} + +# Hosts that are valid for accessing this site. For development, empty list is +# sufficient. +ALLOWED_HOSTS = [] + +# Local time zone for development environment. +TIME_ZONE = 'Europe/Stockholm' diff --git a/project/project_name/settings/production.py b/project/project_name/settings/production.py new file mode 100644 index 0000000000000000000000000000000000000000..e2f8211ce31e6037e672a5931de88a843436b4c4 --- /dev/null +++ b/project/project_name/settings/production.py @@ -0,0 +1,66 @@ +# Production environment settings for project {{ project_name }}. + +# +# This configuration file is used to define settins for the production +# environment. +# + +# Import the exception for signaling invalid configuration. No other +# Django-specific definitions should be imported here. +from django.core.exceptions import ImproperlyConfigured + +# Import the base settings. +from .base import * + +# Import the credentials. +try: + from .credentials import DATABASE_PASSWORDS +except ImportError: + raise ImproperlyConfigured("Please configure the DATABASE_PASSWORDS in credentials.py.") + +try: + from .credentials import SECRET_KEY +except ImportError: + raise ImproperlyConfigured("Please configure the SECRET_KEY in credentials.py.") + +# Debugging should normally be disabled in production environment, but may be +# necessary in case of serious issues that cannot be reproduced in test +# environment. +DEBUG = False +for template_config in TEMPLATES: + template_config['OPTIONS']['debug']=False + +# Site administrators and managers. +ADMINS = ( + # ('Your Name', 'your_email@example.com'), +) +MANAGERS = ADMINS + +# Database configuration. Avoid using sqlite3 for production environments. +DATABASES = { + 'default': { + # Database engine to use. Set it to 'postgresql_psycopg2', 'mysql', + # 'sqlite3' or 'oracle' (keep the django.db.backends prefix). + 'ENGINE': 'django.db.backends.', + # Name of database, or path to database file if using sqlite3. + 'NAME': '', + # Username for logging-in into database server. Not required for + # sqlite3. + 'USER': '', + # Password for logging-in into database server. Should be read from + # credentials.py. + 'PASSWORD': DATABASE_PASSWORDS['default'], + # IP or resolvable name of the database server. + 'HOST': '127.0.0.1', + # Port on which the database server accepts incoming connections. If not + # specified, engine-specific port is set automatically. + 'PORT': '', + } +} + +# Hosts that are valid for accessing this site. Must be set for production +# environment. +ALLOWED_HOSTS = [] + +# Local time zone for production environment. +TIME_ZONE = 'Europe/Stockholm' diff --git a/project/project_name/settings/sample_credentials.py b/project/project_name/settings/sample_credentials.py new file mode 100644 index 0000000000000000000000000000000000000000..1556bf1f5475a99d81b15653288f377e2453c877 --- /dev/null +++ b/project/project_name/settings/sample_credentials.py @@ -0,0 +1,15 @@ +# Sample credentials.py file. + +# +# This file contains a sample of how the site-specific credentials.py file +# should look like. +# + +# Secret key should be unique and kept secret. It should also be sufficiently +# complex to prevent brute-forcing. +SECRET_KEY = '' + +# Passwords for one or more databases used by the site. +DATABASE_PASSWORDS = { + 'default': '', + } diff --git a/project/project_name/settings/testing.py b/project/project_name/settings/testing.py new file mode 100644 index 0000000000000000000000000000000000000000..9894a141ba85181aecd291a8b7785857992d9a90 --- /dev/null +++ b/project/project_name/settings/testing.py @@ -0,0 +1,66 @@ +# Testing environment settings for project {{ project_name }}. + +# +# This configuration file is used to define settings for the testing +# environment. +# + +# Import the exception for signaling invalid configuration. No other +# Django-specific definitions should be imported here. +from django.core.exceptions import ImproperlyConfigured + +# Import the base settings. +from .base import * + +# Import the credentials. +try: + from .credentials import DATABASE_PASSWORDS +except ImportError: + raise ImproperlyConfigured("Please configure the DATABASE_PASSWORDS in credentials.py.") + +try: + from .credentials import SECRET_KEY +except ImportError: + raise ImproperlyConfigured("Please configure the SECRET_KEY in credentials.py.") + +# Debugging should normally be disabled in test environment, but may be +# necessary in some cases. +DEBUG = False +for template_config in TEMPLATES: + template_config['OPTIONS']['debug']=False + +# Site administrators and managers. +ADMINS = ( + # ('Your Name', 'your_email@example.com'), +) +MANAGERS = ADMINS + +# Database configuration. Testing environment should use database configuration +# as similar to production as possible. +DATABASES = { + 'default': { + # Database engine to use. Set it to 'postgresql_psycopg2', 'mysql', + # 'sqlite3' or 'oracle' (keep the django.db.backends prefix). + 'ENGINE': 'django.db.backends.', + # Name of database, or path to database file if using sqlite3. + 'NAME': '', + # Username for logging-in into database server. Not required for + # sqlite3. + 'USER': '', + # Password for logging-in into database server. Should be read from + # credentials.py. + 'PASSWORD': DATABASE_PASSWORDS['default'], + # IP or resolvable name of the database server. + 'HOST': '127.0.0.1', + # Port on which the database server accepts incoming connections. If not + # specified, engine-specific port is set automatically. + 'PORT': '', + } +} + +# Hosts that are valid for accessing this site. Must be set for testing +# environment. +ALLOWED_HOSTS = [] + +# Local time zone for testing environment. +TIME_ZONE = 'Europe/Stockholm'