From a598727888948f479b1dda6f880a6ab738fcc8fd Mon Sep 17 00:00:00 2001 From: codex_a Date: Sat, 28 Feb 2026 20:57:54 +0000 Subject: [PATCH] fix: fix all dev static/media serving issues - Remove WhiteNoise from MIDDLEWARE in development: it intercepts /static/ requests and serves from STATIC_ROOT, which is empty without collectstatic. Django's runserver serves static files natively with DEBUG=True. - Switch to StaticFilesStorage in dev: no manifest required. - Add media URL pattern in DEBUG mode: runserver does not serve MEDIA_ROOT automatically, so uploaded images were 404ing in local dev. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- config/settings/development.py | 8 +++++--- config/urls.py | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config/settings/development.py b/config/settings/development.py index c35364e..fd19e5d 100644 --- a/config/settings/development.py +++ b/config/settings/development.py @@ -4,9 +4,11 @@ DEBUG = True INTERNAL_IPS = ["127.0.0.1"] -# Use plain static file storage in dev — CompressedManifestStaticFilesStorage -# (set in base.py) requires collectstatic to have been run and will 404 on -# every asset otherwise. +# Drop WhiteNoise in dev — it serves from STATIC_ROOT which is empty without +# collectstatic, so it 404s every asset. Django's runserver serves static and +# media files natively when DEBUG=True (via django.contrib.staticfiles + the +# media URL pattern in urls.py). +MIDDLEWARE = [m for m in MIDDLEWARE if m != "whitenoise.middleware.WhiteNoiseMiddleware"] STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage" try: diff --git a/config/urls.py b/config/urls.py index 2e22f1f..90e0544 100644 --- a/config/urls.py +++ b/config/urls.py @@ -1,3 +1,5 @@ +from django.conf import settings +from django.conf.urls.static import static from django.contrib import admin from django.urls import include, path from django.views.generic import RedirectView @@ -21,3 +23,6 @@ urlpatterns = [ path("admin/", RedirectView.as_view(url="/cms/", permanent=False)), path("", include(wagtail_urls)), ] + +if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -- 2.49.1