serve media previews
All checks were successful
Build and Push Docker Image / build (push) Successful in 45s
All checks were successful
Build and Push Docker Image / build (push) Successful in 45s
This commit is contained in:
@@ -14,10 +14,13 @@ 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 urllib.parse import urlsplit
|
||||
|
||||
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.urls import include, path, re_path
|
||||
from django.views.static import serve
|
||||
|
||||
from santehray import views
|
||||
|
||||
@@ -30,5 +33,13 @@ urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
# Serve uploaded media through Django so item previews work in preview/production
|
||||
# deployments too. A dedicated web server or object storage can replace this later.
|
||||
if settings.MEDIA_URL and not urlsplit(settings.MEDIA_URL).netloc:
|
||||
urlpatterns += [
|
||||
re_path(
|
||||
rf"^{re.escape(settings.MEDIA_URL.lstrip('/'))}(?P<path>.*)$",
|
||||
serve,
|
||||
{"document_root": settings.MEDIA_ROOT},
|
||||
),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user