From 0f3a50f368cfe17f76e48a793d257ed204043c99 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 5 May 2020 07:39:57 +0200 Subject: [PATCH] Serve static files in every case --- tfjm/urls.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tfjm/urls.py b/tfjm/urls.py index 97c2280..c5cfc02 100644 --- a/tfjm/urls.py +++ b/tfjm/urls.py @@ -13,10 +13,12 @@ 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 django.conf import settings -from django.conf.urls.static import static from django.contrib import admin -from django.urls import path, include +from django.contrib.staticfiles.views import serve +from django.urls import path, include, re_path from django.views.defaults import bad_request, permission_denied, page_not_found, server_error from django.views.generic import TemplateView @@ -37,8 +39,9 @@ urlpatterns = [ path('api/', include('api.urls')), ] -# urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) -urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +urlpatterns += [ + re_path(r'^%s(?P.*)$' % re.escape(settings.STATIC_URL.lstrip('/')), serve), +] handler400 = bad_request handler403 = permission_denied