serving django media (user uploaded) files in production

烂漫一生 提交于 2020-01-03 17:50:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!