hello to all,
I’m trying to make a feature that allows users to change their profile picture but when I put it in production the images don’t exist.
Is there any way to serve media files with django in production?
my configuration in settings.py is:
MEDIA_URL = '/ media /'
MEDIA_ROOT = str (BASE_DIR.joinpath ('media'))
and in urls.py:
urlpatterns = [
] + static (settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
How are you running the server in production?
with the free version of heroku
Django does not support serving media files with DEBUG set to False. Heroku’s documentation suggests using Whitenoise: Django and Static Assets | Heroku Dev Center.
Heroku does not preserve user-uploaded media files between dyno restarts. I usually go straight to AWS s3 and is pretty easy to set up. Heroku also has data stores that can be used, but I have yet to try them. Cloudinary is also an option.
on this same question, linux ubuntu 20.0, i can access my path to http://ip:8000/media/default.jpg,
but when i register through the form i get
[Errno 2] No such file or directory: ‘/media/default.jpg’
please any help