diff --git a/src/comics/urls.py b/src/comics/urls.py index 841b6866..43937fcb 100644 --- a/src/comics/urls.py +++ b/src/comics/urls.py @@ -1,8 +1,10 @@ +import re + 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.urls import include, path, re_path from django.views.generic.base import TemplateView +from django.views.static import serve urlpatterns = [ # Robots not welcome @@ -30,9 +32,15 @@ ] -# Let Django host media if doing local development on runserver +# Let Django host media if nothing in front of it handles the request. if not settings.MEDIA_URL.startswith("http"): - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + urlpatterns += [ + re_path( + r"^%s(?P.*)$" % re.escape(settings.MEDIA_URL.lstrip("/")), + serve, + kwargs={"document_root": settings.MEDIA_ROOT}, + ), + ] # Include debug_toolbar during development