From 3debd75f18bc8c719151107682978107a9476846 Mon Sep 17 00:00:00 2001 From: Tobias Mieves <tobias.mieves@tu-dortmund.de> Date: Tue, 26 Sep 2023 22:57:09 +0200 Subject: [PATCH] fix: Configure Django to serve static and media files itself For small sites this is ok. For bigger sites a file server such as nginx or apache should be used. --- core/urls.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/urls.py b/core/urls.py index 77e9246..5d19d70 100644 --- a/core/urls.py +++ b/core/urls.py @@ -13,14 +13,15 @@ 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')) """ -from django.conf.urls.static import static -from django.contrib import admin -from django.urls import path, include - from core import settings +from django.contrib import admin +from django.urls import path, include, re_path +from django.views.static import serve urlpatterns = [ path("admin/", admin.site.urls), path("accounts/", include("django.contrib.auth.urls")), path("", include("{{app_to_install}}.urls")), -] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + re_path(r"^media/(?P<path>.*)$", serve, {"document_root": settings.MEDIA_ROOT}), + re_path(r"^static/(?P<path>.*)$", serve, {"document_root": settings.STATIC_ROOT}), +] -- GitLab