125 lines
3.7 KiB
Python
125 lines
3.7 KiB
Python
import os
|
|
from pathlib import Path
|
|
import environ
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
env = environ.Env(
|
|
DEBUG=(bool, True),
|
|
ALLOWED_HOSTS=(list, ['*']),
|
|
CSRF_TRUSTED_ORIGINS=(list, ['*']),
|
|
)
|
|
|
|
# Read .env if present
|
|
environ.Env.read_env(BASE_DIR / '.env')
|
|
|
|
SECRET_KEY = env('SECRET_KEY', default='dev-secret-key-change-in-production-please-12345')
|
|
DEBUG = env('DEBUG')
|
|
ALLOWED_HOSTS = env('ALLOWED_HOSTS')
|
|
CSRF_TRUSTED_ORIGINS = env('CSRF_TRUSTED_ORIGINS')
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'channels',
|
|
'core',
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'whitenoise.middleware.WhiteNoiseMiddleware',
|
|
'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 = 'config.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [BASE_DIR / 'templates'],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.debug',
|
|
'django.template.context_processors.request',
|
|
'core.context_processors.sidebar_context',
|
|
'core.context_processors.sidebar_context',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'config.wsgi.application'
|
|
ASGI_APPLICATION = 'config.asgi.application'
|
|
|
|
# Database
|
|
DATABASE_URL = env('DATABASE_URL', default=f'sqlite:///{BASE_DIR}/db.sqlite3')
|
|
if DATABASE_URL.startswith('sqlite'):
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': BASE_DIR / 'db.sqlite3',
|
|
}
|
|
}
|
|
else:
|
|
import dj_database_url
|
|
DATABASES = {'default': dj_database_url.config(default=DATABASE_URL, conn_max_age=600)}
|
|
|
|
# Channels / Redis
|
|
REDIS_URL = env('REDIS_URL', default=None)
|
|
if REDIS_URL:
|
|
CHANNEL_LAYERS = {
|
|
'default': {
|
|
'BACKEND': 'channels_redis.core.RedisChannelLayer',
|
|
'CONFIG': {'hosts': [REDIS_URL]},
|
|
}
|
|
}
|
|
else:
|
|
CHANNEL_LAYERS = {
|
|
'default': {
|
|
'BACKEND': 'channels.layers.InMemoryChannelLayer',
|
|
}
|
|
}
|
|
|
|
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'},
|
|
]
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
TIME_ZONE = 'UTC'
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
STATIC_URL = '/static/'
|
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
|
STATICFILES_DIRS = [BASE_DIR / 'static']
|
|
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
LOGIN_URL = '/login/'
|
|
LOGIN_REDIRECT_URL = '/'
|
|
LOGOUT_REDIRECT_URL = '/login/'
|
|
|
|
# Production security (applied when DEBUG=False)
|
|
if not DEBUG:
|
|
SECURE_SSL_REDIRECT = True
|
|
SECURE_HSTS_SECONDS = 31536000
|
|
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
|
|
SESSION_COOKIE_SECURE = True
|
|
CSRF_COOKIE_SECURE = True
|
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|