From 0abc42176663503c60bd2ada27b79f58af4b9e71 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 17 Jun 2026 18:41:41 +0300 Subject: [PATCH] Serve Django admin static assets --- .gitignore | 1 + apps/backend/hub_backend/settings.py | 10 ++++++++++ apps/backend/requirements.txt | 1 + compose.yaml | 3 ++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6c30797..21bf1cf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .venv/ __pycache__/ *.py[cod] +apps/backend/staticfiles/ .pytest_cache/ .ruff_cache/ .mypy_cache/ diff --git a/apps/backend/hub_backend/settings.py b/apps/backend/hub_backend/settings.py index c8d4182..4704bdb 100644 --- a/apps/backend/hub_backend/settings.py +++ b/apps/backend/hub_backend/settings.py @@ -38,6 +38,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", + "whitenoise.middleware.WhiteNoiseMiddleware", "hub_platform.http.middleware.LocalCorsMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", @@ -102,6 +103,15 @@ USE_I18N = True USE_TZ = True STATIC_URL = "static/" +STATIC_ROOT = BASE_DIR / "staticfiles" +STORAGES = { + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + }, + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, +} DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" REST_FRAMEWORK = { diff --git a/apps/backend/requirements.txt b/apps/backend/requirements.txt index 62444f3..7593ee1 100644 --- a/apps/backend/requirements.txt +++ b/apps/backend/requirements.txt @@ -4,6 +4,7 @@ psycopg[binary]>=3.2,<3.3 redis>=5.2,<5.3 uvicorn[standard]>=0.34,<0.35 gunicorn>=23.0,<24.0 +whitenoise>=6.9,<6.10 pytest>=8.4,<8.5 pytest-django>=4.11,<4.12 ruff>=0.12,<0.13 diff --git a/compose.yaml b/compose.yaml index 72a5b4a..95f3f66 100644 --- a/compose.yaml +++ b/compose.yaml @@ -36,7 +36,8 @@ services: dockerfile: apps/backend/Dockerfile env_file: *hub-env command: > - sh -c "python manage.py migrate && + sh -c "python manage.py collectstatic --noinput && + python manage.py migrate && uvicorn hub_backend.asgi:application --host 0.0.0.0 --port 8000" ports: - "${BACKEND_PORT:-8010}:8000"