问题
I have deployed my django website onto webfaction hosting service and i am struggling to find how i can serve user uploaded media files in production. There are lot of question regarding how to serve media files in development, but there seems to be nothing about serving media (user uploaded ) files in production.
At present, my django app looks like below in production.
django_project
|
---> media
---> static (these are served through collectstatic and no problem with this)
---> appname1
---> appname2
--->project_name
|
---> settings.py
And my
MEDIA_ROOT = /django_project/media/
MEDIA_URL = www.website.com/media/
There are lot of user uploaded images that are stored in this media folder. Now when i open website, none of the images are loading up. Can someone help how i can serve media files in production.
Thanks
Sreekanth
回答1:
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
来源:https://stackoverflow.com/questions/15707680/serving-django-media-user-uploaded-files-in-production