Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve Django media files from render.com disk

I'm deploying my Django application via render.com and I'm using a disk to serve the media files uploaded by the user. I can tell that the media files are being uploaded to the right place by using the render.com shell:

Image files appear in the media folder

However, when I try retrieving the image files in my website template, they don't appear.

Images aren't appearing on the website

My MEDIA_ROOT is "/var/www/[mysite].onrender.com/media/" ([mysite] replaced with the application name) and my MEDIA_URL is '/media/'. On render, the mount path of my disk is '/opt/render/project/src/media/'.

like image 808
cyborg48 Avatar asked Jul 22 '26 13:07

cyborg48


1 Answers

Just got it working, actually! Added this to my urls.py:

from django.views.static import serve
from django.urls import re_path

urlpatterns += [
    re_path(r'^media/(?P<path>.*)$', serve, {
        'document_root': settings.MEDIA_ROOT,
    }),
]
like image 64
cyborg48 Avatar answered Jul 25 '26 05:07

cyborg48



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!