diff --git a/config/settings.py b/config/settings.py index f3194d3..c2ce1b2 100644 --- a/config/settings.py +++ b/config/settings.py @@ -1,5 +1,6 @@ import os import sys +import dj_database_url from pathlib import Path from django.utils.translation import gettext_lazy as _ @@ -21,6 +22,7 @@ CSRF_TRUSTED_ORIGINS = [ 'https://*.flatlogic.app', 'https://*.flatlogic.run', 'https://*.flatlogic.com', + 'https://*.herokuapp.com', 'http://localhost:8000', 'http://127.0.0.1:8000', ] @@ -41,6 +43,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', '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 # https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators @@ -139,6 +147,13 @@ STATICFILES_DIRS = [ 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) if (BASE_DIR / 'node_modules').exists(): STATICFILES_DIRS.append(BASE_DIR / 'node_modules') diff --git a/requirements.txt b/requirements.txt index a373ab8..8f5394b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,5 @@ gunicorn==21.2.0 requests openpyxl WeasyPrint +dj-database-url +whitenoise \ No newline at end of file