Last active
February 25, 2017 16:35
-
-
Save 0xKD/e7196e77ae19ba4da24d7570935d8ea3 to your computer and use it in GitHub Desktop.
Django settings.py template (using django-environ)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root = true | |
; Always use Unix style new lines with new line ending on every file and trim whitespace | |
[*] | |
end_of_line = lf | |
insert_final_newline = true | |
trim_trailing_whitespace = true | |
; Python: PEP8 defines 4 spaces for indentation | |
[*.py] | |
charset = utf-8 | |
indent_style = space | |
indent_size = 4 | |
; Salt state files, YAML format, 2 spaces | |
[*.sls, *.yaml, *.yml] | |
indent_style = space | |
indent_size = 2 | |
; HTML/CSS/JS | |
[*.html,*.css,*.js] | |
charset = utf-8 | |
indent_style = space | |
indent_size = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEBUG=True | |
SECRET_KEY=SSd2ZSBjb21lIHRvIHRlbGwgeW91IHdobyBraWxsZWQgb3VyIGtpbmcu | |
ALLOWED_HOSTS=localhost | |
DATABASE_URL=postgresql://127.0.0.1:5432/db | |
CACHE_URL=rediscache://localhost:6379/1 | |
STATIC_ROOT=/usr/local/var/www/project/static | |
MEDIA_ROOT=/usr/local/var/www/project/media |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Created by .ignore support plugin (hsz.mobi) | |
### JetBrains template | |
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm | |
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | |
# idea | |
.idea/ | |
## File-based project format: | |
*.iws | |
## Plugin-specific files: | |
# IntelliJ | |
/out/ | |
# mpeltonen/sbt-idea plugin | |
.idea_modules/ | |
# JIRA plugin | |
atlassian-ide-plugin.xml | |
# Crashlytics plugin (for Android Studio and IntelliJ) | |
com_crashlytics_export_strings.xml | |
crashlytics.properties | |
crashlytics-build.properties | |
fabric.properties | |
### VirtualEnv template | |
# Virtualenv | |
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ | |
.Python | |
[Bb]in | |
[Ii]nclude | |
[Ll]ib | |
[Ll]ib64 | |
[Ll]ocal | |
[Ss]cripts | |
pyvenv.cfg | |
.venv | |
pip-selfcheck.json | |
### Python template | |
# Byte-compiled / optimized / DLL files | |
*$py.class | |
__pycache__/ | |
*.py[cod] | |
# C extensions | |
*.so | |
# Distribution / packaging | |
env/ | |
build/ | |
develop-eggs/ | |
dist/ | |
downloads/ | |
eggs/ | |
.eggs/ | |
lib/ | |
lib64/ | |
parts/ | |
sdist/ | |
var/ | |
wheels/ | |
*.egg-info/ | |
.installed.cfg | |
*.egg | |
# PyInstaller | |
# Usually these files are written by a python script from a template | |
# before PyInstaller builds the exe, so as to inject date/other infos into it. | |
*.manifest | |
*.spec | |
# Installer logs | |
pip-log.txt | |
pip-delete-this-directory.txt | |
# Unit test / coverage reports | |
htmlcov/ | |
.tox/ | |
.coverage | |
.coverage.* | |
.cache | |
nosetests.xml | |
coverage.xml | |
*,cover | |
.hypothesis/ | |
# Translations | |
*.mo | |
*.pot | |
# Django stuff: | |
*.log | |
local_settings.py | |
# Flask stuff: | |
instance/ | |
.webassets-cache | |
# Scrapy stuff: | |
.scrapy | |
# Sphinx documentation | |
docs/_build/ | |
# PyBuilder | |
target/ | |
# Jupyter Notebook | |
.ipynb_checkpoints | |
.ipynb | |
# pyenv | |
.python-version | |
# celery beat schedule file | |
celerybeat-schedule | |
# SageMath parsed files | |
*.sage.py | |
# dotenv | |
.env | |
# virtualenv | |
venv/ | |
ENV/ | |
# Spyder project settings | |
.spyderproject | |
# Rope project settings | |
.ropeproject | |
### macOS template | |
*.DS_Store | |
.AppleDouble | |
.LSOverride | |
# Icon must end with two \r | |
Icon | |
# Thumbnails | |
._* | |
# Files that might appear in the root of a volume | |
.DocumentRevisions-V100 | |
.fseventsd | |
.Spotlight-V100 | |
.TemporaryItems | |
.Trashes | |
.VolumeIcon.icns | |
.com.apple.timemachine.donotpresent | |
# Directories potentially created on remote AFP share | |
.AppleDB | |
.AppleDesktop | |
Network Trash Folder | |
Temporary Items | |
.apdisk | |
### Vim template | |
# swap | |
[._]*.s[a-v][a-z] | |
[._]*.sw[a-p] | |
[._]s[a-v][a-z] | |
[._]sw[a-p] | |
# session | |
Session.vim | |
# temporary | |
.netrwhist | |
*~ | |
# custom | |
db.sqlite3 | |
tags | |
staticfiles | |
mediafiles |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import environ | |
import os | |
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | |
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) | |
BASE_DIR = os.path.dirname(PROJECT_DIR) | |
root = environ.Path(__file__) | |
env = environ.Env(DEBUG=(bool, True),) | |
environ.Env.read_env() | |
SITE_ROOT = root() | |
# Quick-start development settings - unsuitable for production | |
# SECURITY WARNING: keep the secret key used in production secret! | |
SECRET_KEY = env('SECRET_KEY') | |
# SECURITY WARNING: don't run with debug turned on in production! | |
DEBUG = env('DEBUG', default=True) | |
ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=['*']) | |
# Application definition | |
INSTALLED_APPS = [ | |
'django.contrib.admin', | |
'django.contrib.auth', | |
'django.contrib.contenttypes', | |
'django.contrib.sessions', | |
'django.contrib.messages', | |
'django.contrib.staticfiles', | |
'django.contrib.gis', | |
'core', | |
] | |
MIDDLEWARE = [ | |
'django.middleware.security.SecurityMiddleware', | |
'django.contrib.sessions.middleware.SessionMiddleware', | |
'django.middleware.common.CommonMiddleware', | |
'django.middleware.csrf.CsrfViewMiddleware', | |
'django.contrib.auth.middleware.AuthenticationMiddleware', | |
'django.contrib.messages.middleware.MessageMiddleware', | |
'django.middleware.clickjacking.XFrameOptionsMiddleware', | |
] | |
ROOT_URLCONF = '<project>.urls' | |
TEMPLATES = [ | |
{ | |
'BACKEND': 'django.template.backends.django.DjangoTemplates', | |
'DIRS': [], | |
'APP_DIRS': True, | |
'OPTIONS': { | |
'context_processors': [ | |
'django.template.context_processors.debug', | |
'django.template.context_processors.request', | |
'django.contrib.auth.context_processors.auth', | |
'django.contrib.messages.context_processors.messages', | |
], | |
}, | |
}, | |
] | |
WSGI_APPLICATION = '<project>.wsgi.application' | |
# Database & Cache | |
DATABASES = { | |
'default': env.db(), | |
} | |
CACHES = { | |
'default': env.cache(), | |
} | |
# Password validation | |
AUTH_PASSWORD_VALIDATORS = [ | |
{ | |
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', | |
}, | |
{ | |
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', | |
}, | |
{ | |
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', | |
}, | |
{ | |
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', | |
}, | |
] | |
# Internationalization | |
LANGUAGE_CODE = 'en-us' | |
PHONENUMBER_DEFAULT_REGION = 'IN' | |
TIME_ZONE = 'Asia/Calcutta' | |
USE_I18N = True | |
USE_L10N = True | |
USE_TZ = True | |
# Static files (CSS, JavaScript, Images) | |
STATIC_URL = '/static/' | |
MEDIA_URL = '/media/' | |
STATIC_ROOT = env('STATIC_ROOT', default='staticfiles') | |
MEDIA_ROOT = env('MEDIA_ROOT', default='mediafiles') | |
# Local settings | |
local_settings_file = os.path.join(PROJECT_DIR, 'local_settings.py') | |
try: | |
with open(local_settings_file, 'r') as local_settings: | |
print("[!] Using local_settings.py") | |
exec(local_settings.read()) | |
except FileNotFoundError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment