简体   繁体   English

Django是否可以在Production上使用static(settings.MEDIA_URL,document_root = settings.MEDIA_ROOT)提供媒体文件

[英]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.

相关问题 TypeError: 'module' object 不可调用 (+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)) - TypeError: 'module' object is not callable (+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)) 找不到 Django 管理页面 (404), urls.py + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) - Django Admin Page not found (404), urls.py + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 如何从文件路径中删除 settings.MEDIA_ROOT - How to remove settings.MEDIA_ROOT from file path Django是什么静态的(settings.STATIC_URL,document_root = settings.STATIC_ROOT)实际上DO? - What Does Django static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) Actually DO? Django Production Issue提供媒体根文件 - Django Production Issue Serving Media Root Files Django OSError-[Errno 13]权限被拒绝:'/ media / images'-我的MEDIA_URL和MEDIA_ROOT设置是否错误? - Django OSError - [Errno 13] Permission denied: '/media/images' - are my MEDIA_URL and MEDIA_ROOT settings bad? Django - MEDIA_ROOT和MEDIA_URL - Django - MEDIA_ROOT and MEDIA_URL 麻烦在Django settings.py中更新media_root - trouble updating media_root in django settings.py Django MEDIA_URL 和 MEDIA_ROOT - Django MEDIA_URL and MEDIA_ROOT django 1.9在生产中提供媒体文件 - django 1.9 serve media files in production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM