I am writing a Django application in which users can upload images, and I'm not sure how to serve them. I see two ways:
1- upload them as static files: upload them to the static
folder in my project directory and then run python manage.py collectstatic
, but I donβt know how to run this command automatically every time the file loads, and that seems to be a lot processing, because every time the server uninstalls and restarts everything in my static application.
2- use django.views.static.serve
in my urls.py:
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT, }),
but the document does not recommend it for production.
What is the recommended way to serve user uploaded files?
source share