From ee26d0d9a8445ae23e88c55ad1345f529bea1671 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Wed, 21 Dec 2022 14:56:28 +0100 Subject: [PATCH] Update media file server for debugging --- nummi/nummi/urls.py | 6 ++---- nummi/nummi/views.py | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/nummi/nummi/urls.py b/nummi/nummi/urls.py index 8217719..059f3e9 100644 --- a/nummi/nummi/urls.py +++ b/nummi/nummi/urls.py @@ -22,11 +22,9 @@ from django.conf.urls.static import static from . import views -urlpatterns = [ - path("media/", views.media, name="media"), -] + i18n_patterns( +urlpatterns = [path("media/", views.media, name="media"),] + i18n_patterns( path("", include("main.urls")), path("plot/", include("plot.urls")), path("admin/", admin.site.urls), prefix_default_language=False, -) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +) diff --git a/nummi/nummi/views.py b/nummi/nummi/views.py index a79c117..866279f 100644 --- a/nummi/nummi/views.py +++ b/nummi/nummi/views.py @@ -1,8 +1,13 @@ +from django.conf import settings from django.http import HttpResponse from django.contrib.auth.decorators import login_required +from django.views.static import serve + @login_required def media(request, path): + if settings.DEBUG: + return serve(request, path, settings.MEDIA_ROOT) _res = HttpResponse() _res["Content-Type"] = "" _res["X-Accel-Redirect"] = "/internal/media/" + path