Overthinker / core /settings.py
Ashutosh-AIBOT
Deploy Django app
e5815d0
Raw
History Blame Contribute Delete
5.3 kB
"""
Django settings for core project.
Generated by 'django-admin startproject' using Django 6.0
"""
import os
from pathlib import Path
from dotenv import load_dotenv
# --------------------------------------------------
# BASE DIRECTORY
# --------------------------------------------------
BASE_DIR = Path(__file__).resolve().parent.parent
load_dotenv(BASE_DIR / ".env")
# --------------------------------------------------
# SECURITY
# --------------------------------------------------
SECRET_KEY = os.getenv("SECRET_KEY", "django-insecure-change-this-in-production")
DEBUG=False
allowed_hosts_env = os.getenv("ALLOWED_HOSTS", "")
if allowed_hosts_env:
ALLOWED_HOSTS = [host.strip() for host in allowed_hosts_env.split(",")]
else:
if not DEBUG:
ALLOWED_HOSTS = ["localhost", "127.0.0.1", "web", "django_nginx"]
else:
ALLOWED_HOSTS = []
print("DEBUG from env:", os.getenv("DEBUG"))
print("DEBUG after parsing:", DEBUG)
print("ALLOWED_HOSTS:", ALLOWED_HOSTS)
# --------------------------------------------------
# APPLICATIONS
# --------------------------------------------------
INSTALLED_APPS = [
# Django default
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
# Mini apps
"universe",
"testaccounts",
"testprofiles",
"study",
"collection",
"portfolio",
"xomni",
]
SITE_ID = 1
# --------------------------------------------------
# MIDDLEWARE
# --------------------------------------------------
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",
]
# --------------------------------------------------
# URL CONFIG
# --------------------------------------------------
ROOT_URLCONF = "core.urls"
# --------------------------------------------------
# TEMPLATES
# --------------------------------------------------
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"], # GLOBAL templates
"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
# --------------------------------------------------
WSGI_APPLICATION = "core.wsgi.application"
# --------------------------------------------------
# DATABASE
# --------------------------------------------------
DATABASE_ENGINE = os.getenv("DATABASE_ENGINE", "django.db.backends.sqlite3")
DATABASES = {
"default": {
"ENGINE": DATABASE_ENGINE,
"NAME": os.getenv("DATABASE_NAME", BASE_DIR / "db.sqlite3"),
"USER": os.getenv("DATABASE_USER", ""),
"PASSWORD": os.getenv("DATABASE_PASSWORD", ""),
"HOST": os.getenv("DATABASE_HOST", ""),
"PORT": os.getenv("DATABASE_PORT", ""),
}
}
# Add sslmode option only if using PostgreSQL
if DATABASE_ENGINE == "django.db.backends.postgresql":
DATABASES["default"]["OPTIONS"] = {
"sslmode": "require",
}
# --------------------------------------------------
# PASSWORD VALIDATION
# --------------------------------------------------
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",
},
]
# --------------------------------------------------
# AUTH REDIRECTS
# --------------------------------------------------
LOGIN_URL = '/testaccounts/login/'
LOGOUT_REDIRECT_URL = '/testaccounts/login/'
# --------------------------------------------------
# EMAIL (DEV MODE)
# --------------------------------------------------
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# --------------------------------------------------
# INTERNATIONALIZATION
# --------------------------------------------------
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
# --------------------------------------------------
# STATIC FILES
# --------------------------------------------------
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
if DEBUG:
STATICFILES_DIRS = [BASE_DIR / "static"]
# --------------------------------------------------
# DEFAULT PRIMARY KEY
# --------------------------------------------------
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"