|
| 1 | +""" |
| 2 | +Django settings for backend project. |
| 3 | +
|
| 4 | +Generated by 'django-admin startproject' using Django 6.0.3. |
| 5 | +
|
| 6 | +For more information on this file, see |
| 7 | +https://docs.djangoproject.com/en/6.0/topics/settings/ |
| 8 | +
|
| 9 | +For the full list of settings and their values, see |
| 10 | +https://docs.djangoproject.com/en/6.0/ref/settings/ |
| 11 | +""" |
| 12 | + |
| 13 | +import os |
| 14 | +from pathlib import Path |
| 15 | +from urllib.parse import urlparse |
| 16 | + |
| 17 | +# Build paths inside the project like this: BASE_DIR / 'subdir'. |
| 18 | +BASE_DIR = Path(__file__).resolve().parent.parent |
| 19 | + |
| 20 | + |
| 21 | +# Quick-start development settings - unsuitable for production |
| 22 | +# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ |
| 23 | + |
| 24 | +# SECURITY WARNING: keep the secret key used in production secret! |
| 25 | +SECRET_KEY = os.getenv( |
| 26 | + "DJANGO_SECRET_KEY", |
| 27 | + "django-insecure-21r+^amj1kaovh#%uvz22%wa_2luw92q51fe$3_q%@f9*ijb--", |
| 28 | +) |
| 29 | + |
| 30 | +# SECURITY WARNING: don't run with debug turned on in production! |
| 31 | +DEBUG = os.getenv("DJANGO_DEBUG", "").lower() in {"1", "true", "yes", "on"} |
| 32 | + |
| 33 | +ALLOWED_HOSTS = [ |
| 34 | + host.strip() |
| 35 | + for host in os.getenv("DJANGO_ALLOWED_HOSTS", "*").split(",") |
| 36 | + if host.strip() |
| 37 | +] |
| 38 | + |
| 39 | + |
| 40 | +# Application definition |
| 41 | + |
| 42 | +INSTALLED_APPS = [ |
| 43 | + "django.contrib.admin", |
| 44 | + "django.contrib.auth", |
| 45 | + "django.contrib.contenttypes", |
| 46 | + "django.contrib.sessions", |
| 47 | + "django.contrib.messages", |
| 48 | + "django.contrib.staticfiles", |
| 49 | +] |
| 50 | + |
| 51 | +MIDDLEWARE = [ |
| 52 | + "django.middleware.security.SecurityMiddleware", |
| 53 | + "django.contrib.sessions.middleware.SessionMiddleware", |
| 54 | + "django.middleware.common.CommonMiddleware", |
| 55 | + "django.middleware.csrf.CsrfViewMiddleware", |
| 56 | + "django.contrib.auth.middleware.AuthenticationMiddleware", |
| 57 | + "django.contrib.messages.middleware.MessageMiddleware", |
| 58 | + "django.middleware.clickjacking.XFrameOptionsMiddleware", |
| 59 | +] |
| 60 | + |
| 61 | +ROOT_URLCONF = "backend.urls" |
| 62 | + |
| 63 | +TEMPLATES = [ |
| 64 | + { |
| 65 | + "BACKEND": "django.template.backends.django.DjangoTemplates", |
| 66 | + "DIRS": [], |
| 67 | + "APP_DIRS": True, |
| 68 | + "OPTIONS": { |
| 69 | + "context_processors": [ |
| 70 | + "django.template.context_processors.request", |
| 71 | + "django.contrib.auth.context_processors.auth", |
| 72 | + "django.contrib.messages.context_processors.messages", |
| 73 | + ], |
| 74 | + }, |
| 75 | + }, |
| 76 | +] |
| 77 | + |
| 78 | +WSGI_APPLICATION = "backend.wsgi.application" |
| 79 | + |
| 80 | + |
| 81 | +# Database |
| 82 | +# https://docs.djangoproject.com/en/6.0/ref/settings/#databases |
| 83 | + |
| 84 | +database_url = os.getenv("DATABASE_URL", "").strip() |
| 85 | +if database_url.startswith(("postgres://", "postgresql://")): |
| 86 | + parsed = urlparse(database_url) |
| 87 | + DATABASES = { |
| 88 | + "default": { |
| 89 | + "ENGINE": "django.db.backends.postgresql", |
| 90 | + "NAME": parsed.path.lstrip("/") or "postgres", |
| 91 | + "USER": parsed.username or "", |
| 92 | + "PASSWORD": parsed.password or "", |
| 93 | + "HOST": parsed.hostname or "", |
| 94 | + "PORT": parsed.port or 5432, |
| 95 | + } |
| 96 | + } |
| 97 | +else: |
| 98 | + DATABASES = { |
| 99 | + "default": { |
| 100 | + "ENGINE": "django.db.backends.sqlite3", |
| 101 | + "NAME": Path("/app/data/db.sqlite3"), |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + |
| 106 | +# Password validation |
| 107 | +# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators |
| 108 | + |
| 109 | +AUTH_PASSWORD_VALIDATORS = [ |
| 110 | + { |
| 111 | + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", |
| 112 | + }, |
| 113 | + { |
| 114 | + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", |
| 115 | + }, |
| 116 | + { |
| 117 | + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", |
| 118 | + }, |
| 119 | + { |
| 120 | + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", |
| 121 | + }, |
| 122 | +] |
| 123 | + |
| 124 | + |
| 125 | +# Internationalization |
| 126 | +# https://docs.djangoproject.com/en/6.0/topics/i18n/ |
| 127 | + |
| 128 | +LANGUAGE_CODE = "en-us" |
| 129 | + |
| 130 | +TIME_ZONE = "UTC" |
| 131 | + |
| 132 | +USE_I18N = True |
| 133 | + |
| 134 | +USE_TZ = True |
| 135 | + |
| 136 | + |
| 137 | +# Static files (CSS, JavaScript, Images) |
| 138 | +# https://docs.djangoproject.com/en/6.0/howto/static-files/ |
| 139 | + |
| 140 | +STATIC_URL = "static/" |
| 141 | +STATIC_ROOT = BASE_DIR / "staticfiles" |
0 commit comments