You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When DEBUG = False, Django doesn’t serve media files by default. This is normal because in production, media files are usually served by a web server like Nginx or Apache, not Django.
If you need to serve media files temporarily while DEBUG = False, you can replace the current code with this in the settings.py file:
from django.conf import settings
from django.urls import path
from django.views.static import serve
if not settings.DEBUG:
urlpatterns += [
path('media/<path:path>', serve, {'document_root': settings.MEDIA_ROOT}),
]
else:
urlpatterns
+= static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
This will make Django serve media files even in production, but it’s not recommended for long-term use in a live environment. For production, it’s better to configure a web server or storage service to handle media files.
We are closing this issue due to inactivity. It seems that there hasn't been any recent activity or discussion, and we believe it may have been resolved or is no longer relevant.
If you feel this issue is still important and should be addressed, please feel free to reopen it or create a new issue with updated details.
Bug Report
Media files doesn't work in production
Description
Steps to Reproduce
Question
Is this the expected behavior?
The text was updated successfully, but these errors were encountered: