From 83bd74d093b2c07d73ff02c8c64f0bf86d45d29c Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 26 Jan 2021 15:00:09 +0100 Subject: [PATCH] MEDIA files were not served by gunicorn when DEBUG=False --- smash/smash/urls.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/smash/smash/urls.py b/smash/smash/urls.py index a192a431..5af09ebd 100644 --- a/smash/smash/urls.py +++ b/smash/smash/urls.py @@ -13,20 +13,23 @@ Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ +import re from django.conf import settings from django.conf.urls import url, include -from django.conf.urls.static import static from django.contrib import admin - +from django.urls import re_path +from django.views.static import serve from two_factor.urls import urlpatterns as tf_urls from web import api_urls from web import urls urlpatterns = [ - url(r'^admin/', admin.site.urls), - url(r'', include(urls)), - url(r'^api/', include(api_urls)), - url(r'', include(tf_urls)), - ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + url(r'^admin/', admin.site.urls), + url(r'', include(urls)), + url(r'^api/', include(api_urls)), + url(r'', include(tf_urls)), + re_path(r'^%s(?P<path>.*)$' % re.escape(settings.MEDIA_URL.lstrip('/')), serve, + {'document_root': settings.MEDIA_ROOT}) +] -- GitLab