Serving django files (user uploaded) in production

I deployed my django website to webfaction web hosting and I am struggling to find how I can serve user-uploaded multimedia files during production. There are many questions about how to use media files in development, but nothing seems to be happening in relation to downloading media files (uploaded by the user).

Currently my django app looks like below.

django_project | ---> media ---> static (these are served through collectstatic and no problem with this) ---> appname1 ---> appname2 --->project_name | ---> settings.py 

And mine

MEDIA_ROOT = / django_project / media /

MEDIA_URL = www.website.com/media/

There are many user-uploaded images that are stored in this media folder. Now when I open the site, not a single image is loaded. Can someone help how I can serve media files during production.

thanks

Srikant

+4
source share
1 answer

You need to use django.views.static.serve, something like this:

 (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'media'}), 

https://docs.djangoproject.com/en/dev/howto/static-files/#serving-other-directories

+1
source

All Articles