From 53fe092d652b4ccf4321ce86da72ca0e02448417 Mon Sep 17 00:00:00 2001 From: vickytechkey Date: Sun, 23 Aug 2026 12:30:35 +0530 Subject: [PATCH] Configure Whitenoise to serve static files in production --- .forgejo/workflows/beta.yml | 1 + core/settings.py | 5 +++++ requirements.txt | 1 + 3 files changed, 7 insertions(+) diff --git a/.forgejo/workflows/beta.yml b/.forgejo/workflows/beta.yml index f3f83f6..72cf4c6 100644 --- a/.forgejo/workflows/beta.yml +++ b/.forgejo/workflows/beta.yml @@ -83,6 +83,7 @@ jobs: # ── 6. Run Database Migrations ───────────────────────────────── ./venv/bin/python manage.py migrate --noinput + ./venv/bin/python manage.py collectstatic --noinput # ── 7. Configure and restart Systemd service ─────────────────── sudo mv /tmp/emailservice.service /etc/systemd/system/emailservice.service diff --git a/core/settings.py b/core/settings.py index 4af6abc..0b523ec 100644 --- a/core/settings.py +++ b/core/settings.py @@ -46,6 +46,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -133,6 +134,10 @@ USE_TZ = True # https://docs.djangoproject.com/en/6.1/howto/static-files/ STATIC_URL = 'static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') +# Simplified static file serving. +# https://whitenoise.readthedocs.io/en/latest/django.html#add-compression-and-caching-support +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' MEDIA_URL = 'media/' MEDIA_ROOT = BASE_DIR / 'media' diff --git a/requirements.txt b/requirements.txt index 02f3af4..4625341 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,3 +13,4 @@ six==1.17.0 sqlparse==0.6.0 urllib3==2.7.0 gunicorn==22.0.0 +whitenoise==6.7.0