chore: add heroku compatibility (whitenoise, dj-database-url)

This commit is contained in:
Flatlogic Bot 2026-02-14 09:58:46 +00:00
parent e79a5075db
commit 79550235ff
2 changed files with 17 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import os import os
import sys import sys
import dj_database_url
from pathlib import Path from pathlib import Path
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -21,6 +22,7 @@ CSRF_TRUSTED_ORIGINS = [
'https://*.flatlogic.app', 'https://*.flatlogic.app',
'https://*.flatlogic.run', 'https://*.flatlogic.run',
'https://*.flatlogic.com', 'https://*.flatlogic.com',
'https://*.herokuapp.com',
'http://localhost:8000', 'http://localhost:8000',
'http://127.0.0.1:8000', 'http://127.0.0.1:8000',
] ]
@ -41,6 +43,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware', 'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
@ -87,6 +90,11 @@ DATABASES = {
} }
} }
# Use DATABASE_URL if it is set (standard for Heroku)
db_from_env = dj_database_url.config(conn_max_age=600)
if db_from_env:
DATABASES['default'].update(db_from_env)
# Password validation # Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
@ -139,6 +147,13 @@ STATICFILES_DIRS = [
BASE_DIR / "assets", BASE_DIR / "assets",
] ]
# Whitenoise storage for compressed and cached static files
STORAGES = {
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
# Conditionally add node_modules if it exists (prevents W004 warning) # Conditionally add node_modules if it exists (prevents W004 warning)
if (BASE_DIR / 'node_modules').exists(): if (BASE_DIR / 'node_modules').exists():
STATICFILES_DIRS.append(BASE_DIR / 'node_modules') STATICFILES_DIRS.append(BASE_DIR / 'node_modules')

View File

@ -5,3 +5,5 @@ gunicorn==21.2.0
requests requests
openpyxl openpyxl
WeasyPrint WeasyPrint
dj-database-url
whitenoise