Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media files doesn't work in production #441

Closed
h3cksamrat opened this issue Dec 27, 2024 · 2 comments
Closed

Media files doesn't work in production #441

h3cksamrat opened this issue Dec 27, 2024 · 2 comments

Comments

@h3cksamrat
Copy link

Bug Report

Media files doesn't work in production

Description

# File: horilla/urls.py Line: 48
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Steps to Reproduce

  1. set DEBUG = False

Question

Is this the expected behavior?

@horilla-opensource
Copy link
Owner

Hi @h3cksamrat,

Thanks for reporting this issue!

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.

With Regards,
Team Horilla

@horilla-opensource
Copy link
Owner

Hi @h3cksamrat ,

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.

With Regards,
Team Horilla

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants