107 lines
3.4 KiB
Python
107 lines
3.4 KiB
Python
import os
|
|
|
|
from django.urls import reverse_lazy
|
|
|
|
|
|
def _get_env_production_mode():
|
|
env_var = os.environ.get("DJANGO_PRODUCTION_MODE", "false")
|
|
return env_var.lower() == "true"
|
|
|
|
|
|
def _get_env_secret_key():
|
|
env_var = os.environ.get("DJANGO_SECRET_KEY")
|
|
assert env_var is not None, "DJANGO_SECRET_KEY environment variable must be set when using production mode"
|
|
assert 30 <= len(env_var) <= 80, "DJANGO_SECRET_KEY should be 30 to 80 characters long"
|
|
return env_var
|
|
|
|
|
|
def _get_env_allowed_hosts():
|
|
env_var = os.environ.get("DJANGO_ALLOWED_HOSTS")
|
|
assert env_var is not None, "DJANGO_ALLOWED_HOSTS environment variable must be set when using production mode"
|
|
return [host.strip() for host in env_var.split(",")]
|
|
|
|
|
|
def _get_env_static_root():
|
|
env_var = os.environ.get("DJANGO_STATIC_ROOT")
|
|
assert env_var is not None, "DJANGO_STATIC_ROOT environment variable must be set when using production mode"
|
|
return env_var
|
|
|
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
PRODUCTION = _get_env_production_mode()
|
|
|
|
if PRODUCTION:
|
|
SECRET_KEY = _get_env_secret_key()
|
|
DEBUG = False
|
|
ALLOWED_HOSTS = _get_env_allowed_hosts()
|
|
STATIC_ROOT = _get_env_static_root()
|
|
else:
|
|
SECRET_KEY = "QetNMYdSKo3kefmltcEeAu52HbyZBxXsROiYesIEwYwnX0rCuv"
|
|
DEBUG = True
|
|
ALLOWED_HOSTS = ["*"]
|
|
|
|
INSTALLED_APPS = [
|
|
"financeplanner",
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
]
|
|
|
|
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 = "financeproject.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 = "financeproject.wsgi.application"
|
|
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.postgresql_psycopg2",
|
|
"HOST": os.environ.get("DB_HOST"),
|
|
"PORT": os.environ.get("DB_PORT"),
|
|
"NAME": os.environ.get("DB_NAME"),
|
|
"USER": os.environ.get("DB_USER"),
|
|
"PASSWORD": os.environ.get("DB_PASSWORD"),
|
|
}
|
|
}
|
|
|
|
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", },
|
|
]
|
|
|
|
LOGIN_URL = reverse_lazy("login")
|
|
LOGIN_REDIRECT_URL = reverse_lazy("finance:index")
|
|
|
|
STATIC_URL = "/static/"
|