在生产中提供django媒体(用户上传)文件的服务 [英] serving django media (user uploaded) files in production

查看:133
本文介绍了在生产中提供django媒体(用户上传)文件的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将django网站部署到了webfaction托管服务上,我正在努力寻找如何在生产中为用户上传的媒体文件提供服务的方法.有关如何在开发中提供媒体文件的问题很多,但似乎在生产中没有提供媒体文件(用户上传的文件).

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.

目前,我的django应用在生产中如下图所示.

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

还有我的

MEDIA_ROOT =/django_project/media/

MEDIA_ROOT = /django_project/media/

MEDIA_URL = www.website.com/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.

谢谢

Sreekanth

Sreekanth

推荐答案

您需要使用django.views.static.serve,如下所示:

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

这篇关于在生产中提供django媒体(用户上传)文件的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆