It is important to separate the media files from your application file system in production for security purposes. You cannot trust your users' input files and therefore you should not be bundled with your application files. So in production, you should use file storage systems provided by various providers.
However, in development, we can get around this by adding the media root as a static file path on the root URL configuration of the project.
To do this we will use the static function from url.static and ensure we are using it only for development purposes.
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
urlpatterns = [ path('admin/', admin.site.urls),
# ... the rest of your URLconf goes here ...
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
urlpatterns = [ path('admin/', admin.site.urls),
# ... the rest of your URLconf goes here ...
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Regards,
Sammy Barasa
On Saturday, November 2, 2024 at 7:09:27 AM UTC+3 RANGA BHARATH JINKA wrote:
Hi,
You can use cloudinary or Firestore storage bucket to store media files.
Thanks
On Fri, 1 Nov, 2024, 6:11 pm ASAMOAH EMMANUEL, <emmanuela...@gmail.com> wrote:Hi All,
I need help serving media files on render. I already serve static files with whitenoise.
I am able to upload media files but cannot serve them. I get file not found.
If it is not possible, are there other alternatives to s3 bucket.
Thanks in advance.--I don't stop when I'm tired, I only stop when the job is done.--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/CABFHQYxovaK2h6S52LOy19uofRzMTAtobY4szMhmGjD2QaZddw%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/09b26ad7-f3a5-4f3d-b777-ec3ac15544b4n%40googlegroups.com.
No comments:
Post a Comment