[英]Is it possible to serve media files by Django on Production with static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
I want to use non-static images for my app. 我想为我的应用程序使用非静态图像。 Meaning that Admin will be able to upload images (and create articles). 这意味着管理员将能够上传图像(并创建文章)。 Users will have read-only access to articles. 用户将具有对文章的只读访问权限。
Would in this case it be possible to use function static() on Production to store and serve images? 在这种情况下,可以在Production上使用函数static()来存储和提供图像吗?
static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Or still I should use only 3rd party resource for storing/serving the images? 还是我应该仅使用第三方资源来存储/保存图像?
The answer happened to be very simple: 答案碰巧很简单:
the function 功能
static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
simply won't work with "Debug = false". 根本无法与“ Debug = false”一起使用。
That's why it can not be used on Production. 这就是为什么它不能在生产中使用的原因。 Here is a quote from documentation : 这是来自文档的报价:
This helper function works only in debug mode and only if the given prefix is local (eg /media/) and not a URL (eg http://media.example.com/ ). 仅在给定前缀是本地(例如/ media /)而不是URL(例如http://media.example.com/ )的情况下,此帮助器功能仅在调试模式下起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.