serve media previews
All checks were successful
Build and Push Docker Image / build (push) Successful in 45s

This commit is contained in:
2026-04-30 16:07:49 +02:00
parent 27187c5e53
commit 812065a34b
2 changed files with 25 additions and 5 deletions

View File

@@ -14,10 +14,13 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
import re
from urllib.parse import urlsplit
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from django.urls import include, path, re_path
from django.views.static import serve
from santehray import views
@@ -30,5 +33,13 @@ urlpatterns = [
path('admin/', admin.site.urls),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# Serve uploaded media through Django so item previews work in preview/production
# deployments too. A dedicated web server or object storage can replace this later.
if settings.MEDIA_URL and not urlsplit(settings.MEDIA_URL).netloc:
urlpatterns += [
re_path(
rf"^{re.escape(settings.MEDIA_URL.lstrip('/'))}(?P<path>.*)$",
serve,
{"document_root": settings.MEDIA_ROOT},
),
]