forked from GoHiTech/docker-django
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
141 lines (121 loc) · 4.62 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
"""
Django settings for Docker image.
Derived from settings generated by 'django-admin startproject' using Django 1.8.18.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
import sys
import socket
from ast import literal_eval
import glob
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
def _gethostbyname(hostname):
try:
socket.gethostbyname(hostname)
return True
except socket.error:
return False
this_module = sys.modules[__name__]
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ROOT_URLCONF = os.getenv('DJANGO_PROJECT_NAME', 'gohitech') + '.urls'
WSGI_APPLICATION = os.getenv('DJANGO_PROJECT_NAME', 'gohitech') + '.wsgi.application'
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', '+hzj(tw!bod_*_xh4u2ml!ylbtx6)2r9bqq2i!evjo!x&pay%2')
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
# Get all Environment variables with a DJANGO_ prefix; remove prefix
#print { k: v for k, v in os.environ.iteritems() if k.startswith('DJANGO_') }
_django_environ = { k[7:]: v for k, v in os.environ.iteritems() if k.startswith('DJANGO_') }
for key in _django_environ:
try:
if (key in {'PROJECT_NAME','SETTINGS_MODULE',}) or (key.startswith('DATABASE_')):
pass
elif key in {'ADMINS','MANAGERS',}:
setattr(this_module, key, tuple(literal_eval(_django_environ[key])))
else:
setattr(this_module, key, literal_eval(_django_environ[key]))
except ValueError,e:
setattr(this_module, key, _django_environ[key])
#print "ValueError for %s: %s (%s)" % (key,_django_environ[key],str(e))
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
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',
],
},
},
]
# CACHES and Database
# https://docs.djangoproject.com/en/1.8/topics/cache/
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
if _gethostbyname('memcached'):
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': socket.gethostbyname('memcached') + ':11211',
},
}
elif _gethostbyname('db'):
if not _gethostbyname('memcached'):
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'cache_table_default',
},
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.getenv('DJANGO_DATABASE_NAME', 'postgres'),
'USER': os.getenv('DJANGO_DATABASE_USER', 'postgres'),
'PASSWORD': os.getenv('DJANGO_DATABASE_PASSWORD', ''),
'HOST': 'db',
'PORT': '5432',
},
}
else:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
},
}
# Provide overrides in settings.d/*.py
config_files = glob.glob(os.path.join(BASE_DIR,'settings.d','*.py'))
try:
for config_f in sorted(config_files):
print "INFO: Execute config file %s" % os.path.abspath(config_f)
execfile(os.path.abspath(config_f))
except TypeError,e:
pass