import os 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" 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 = "LqKSgoFtED4IFYxf01lBi5MEI4ExSayCakwLjyuzytDJ7vuMq9" DEBUG = True ALLOWED_HOSTS = ["*"] INSTALLED_APPS = [ "gaehsnitz", "django.contrib.contenttypes", "django.contrib.staticfiles", ] MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", ] ROOT_URLCONF = "gaehsnitzproject.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", ], }, }, ] WSGI_APPLICATION = "gaehsnitzproject.wsgi.application" TIME_ZONE = "Europe/Berlin" USE_I18N = False USE_L10N = False USE_TZ = True STATIC_URL = "/static/"