· 7 years ago · Feb 12, 2018, 09:52 AM
1"""
2Django settings for davixxa_website project.
3
4Generated by 'django-admin startproject' using Django 1.9.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/1.9/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/1.9/ref/settings/
11"""
12
13import os
14from django.conf.locale.en import formats as en_formats
15en_formats.DATETIME_FORMAT = "F jS, Y H:i"
16
17
18# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
19BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
20
21
22# Quick-start development settings - unsuitable for production
23# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
24
25# SECURITY WARNING: don't run with debug turned on in production!
26DEBUG = False
27DOCKER = False
28
29# SECURITY WARNING: keep the secret key used in production secret!
30if DEBUG:
31 SECRET_KEY = '@snpcev(q2)bjlbq*yw52%xsa#s1lx7t=21shxz!r&9+9$g2^z'
32else:
33 SECRET_KEY = os.environ["DAVIXXA_SECRET_KEY"]
34
35#ALLOWED_HOSTS = ["davixxa.net", "www.davixxa.net", "www.davixxa.ml", "davixxa.ml"]
36ALLOWED_HOSTS = [".davixxa.net", ".davixxa.ml"]
37SECURE_SSL_REDIRECT = False
38
39# Site definition
40SITE = {
41 "url": "https://davixxa.net",
42 "logo_url": "https://pbs.twimg.com/profile_images/685958901431287808/g_DfNBbP_400x400.png",
43 "title": "Davixxa",
44 "description": "RAMBLINGS OF A LAZY WEEB TECH ENTHUSIAST."
45}
46
47# Application definition
48INSTALLED_APPS = [
49 'posts',
50 'projs', # 'projects' collides with the django internal 'projects' namespace
51 'static_pages',
52 'gitlab_watcher',
53 'markdownx',
54 'django.contrib.admin',
55 'django.contrib.auth',
56 'django.contrib.contenttypes',
57 'django.contrib.sessions',
58 'django.contrib.messages',
59 'django.contrib.staticfiles',
60]
61
62MIDDLEWARE_CLASSES = [
63 'django.middleware.security.SecurityMiddleware',
64 'django.contrib.sessions.middleware.SessionMiddleware',
65 'django.middleware.common.CommonMiddleware',
66 'django.middleware.csrf.CsrfViewMiddleware',
67 'django.contrib.auth.middleware.AuthenticationMiddleware',
68 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
69 'django.contrib.messages.middleware.MessageMiddleware',
70 'django.middleware.clickjacking.XFrameOptionsMiddleware',
71]
72
73ROOT_URLCONF = 'davixxa_website.urls'
74
75TEMPLATES = [
76 {
77 'BACKEND': 'django.template.backends.django.DjangoTemplates',
78 'DIRS': [os.path.join(BASE_DIR, 'templates')],
79 'APP_DIRS': True,
80 'OPTIONS': {
81 'context_processors': [
82 'django.template.context_processors.debug',
83 'django.template.context_processors.request',
84 'django.contrib.auth.context_processors.auth',
85 'django.contrib.messages.context_processors.messages',
86 ],
87 },
88 },
89]
90
91WSGI_APPLICATION = 'davixxa_website.wsgi.application'
92
93
94# Database
95# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
96
97if DEBUG:
98 if DOCKER:
99 """If Docker is set, use docker, if not, use a sqlite3 backend."""
100 DATABASES = {
101 'default': {
102 'ENGINE': 'django.db.backends.mysql',
103 'NAME': "davixxa",
104 'USER': "root",
105 'PASSWORD': "redacted",
106 'HOST': "db",
107 'PORT': "3306",
108 }
109 }
110 else:
111 DATABASES = {
112 'default': {
113 'ENGINE': 'django.db.backends.sqlite3',
114 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
115 }
116 }
117else:
118 """Use mysql in production
119 This has been confirmed to be possible, however, the host domain
120 has to be known beforehand such that it can be set to trusted in the DB
121 please contact @kasperfred <kasper@kasperfred.com> for more details
122 """
123 DATABASES = {
124 'default': {
125 #'ENGINE': 'django.db.backends.mysql',
126 'ENGINE': 'mysql.connector.django',
127 'NAME': os.environ['DAVIXXA_DATABASE_NAME'],
128 'USER': os.environ['DAVIXXA_DATABASE_USER'],
129 'PASSWORD': os.environ['DAVIXXA_DATABASE_PASSWORD'],
130 'HOST': os.environ['DAVIXXA_DATABASE_HOST'],
131 'PORT': os.environ['DAVIXXA_DATABASE_PORT'],
132 }
133 }
134
135# HTTPS
136if DEBUG:
137 SECURE_SSL_REDIRECT = False
138 SESSION_COOKIE_SECURE = False
139 CSRF_COOKIE_SECURE = False
140else:
141 SECURE_SSL_REDIRECT = True
142 SESSION_COOKIE_SECURE = True
143 CSRF_COOKIE_SECURE = True
144
145
146# Password validation
147# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
148
149AUTH_PASSWORD_VALIDATORS = [
150 {
151 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
152 },
153 {
154 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
155 },
156 {
157 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
158 },
159 {
160 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
161 },
162]
163
164
165# Internationalization
166# https://docs.djangoproject.com/en/1.9/topics/i18n/
167
168LANGUAGE_CODE = 'en-us'
169
170TIME_ZONE = 'UTC'
171
172USE_I18N = True
173
174USE_L10N = True
175
176USE_TZ = True
177
178
179# Static files (CSS, JavaScript, Images)
180# https://docs.djangoproject.com/en/1.9/howto/static-files/
181
182STATIC_URL = '/static/'
183STATIC_ROOT = BASE_DIR + "/public/static"
184STATICFILES_DIRS = [
185 os.path.join(BASE_DIR, "static"),
186]