File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1616"""
1717from django .contrib import admin
18- from django .urls import path
18+ from django .urls import path , re_path
1919from portfolio import views
2020from django .conf .urls import include
2121from django .conf .urls .static import static
2222from django .conf import settings
23+ from django .views .static import serve
2324
2425urlpatterns = [
2526 path ('admin/' , admin .site .urls ),
2627 path ('' , include ('portfolio.urls' )),
27- ] + static (settings .MEDIA_URL , document_root = settings .MEDIA_ROOT )
28+ ]
29+
30+ # Serve media files in production (Fly.io with persistent volume)
31+ if not settings .DEBUG :
32+ urlpatterns += [
33+ re_path (r'^media/(?P<path>.*)$' , serve , {'document_root' : settings .MEDIA_ROOT }),
34+ ]
35+ else :
36+ urlpatterns += static (settings .MEDIA_URL , document_root = settings .MEDIA_ROOT )
You can’t perform that action at this time.
0 commit comments