Serve static files in every case

This commit is contained in:
Yohann D'ANELLO 2020-05-05 07:39:57 +02:00
parent 6d2612a5ec
commit 0f3a50f368
1 changed files with 7 additions and 4 deletions

View File

@ -13,10 +13,12 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
import re
from django.conf import settings from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin 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.defaults import bad_request, permission_denied, page_not_found, server_error
from django.views.generic import TemplateView from django.views.generic import TemplateView
@ -37,8 +39,9 @@ urlpatterns = [
path('api/', include('api.urls')), path('api/', include('api.urls')),
] ]
# urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += [
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) re_path(r'^%s(?P<path>.*)$' % re.escape(settings.STATIC_URL.lstrip('/')), serve),
]
handler400 = bad_request handler400 = bad_request
handler403 = permission_denied handler403 = permission_denied