我已将我的 django 网站部署到 webfaction 托管服务上,并且我正在努力寻找如何在生产中为用户上传的媒体文件提供服务。关于如何在开发中提供媒体文件存在很多问题,但似乎没有关于在生产中提供媒体(用户上传)文件的信息。
目前,我的 Django 应用程序在生产环境中如下所示。
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/
此媒体文件夹中存储有许多用户上传的图像。
现在,当我打开网站时,没有任何图像加载。
有人可以帮助我如何在生产中提供媒体文件。
Thanks
斯里坎特
您需要使用 django.views.static.serve,如下所示:
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'media'}),
https://docs.djangoproject.com/en/dev/howto/static-files/#serving-other-directories https://docs.djangoproject.com/en/dev/howto/static-files/#serving-other-directories
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)