Django对`MEDIA_ROOT`有何作用? [英] What does Django do with `MEDIA_ROOT`?

查看:79
本文介绍了Django对`MEDIA_ROOT`有何作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django对 MEDIA_ROOT 到底有什么作用?我从来不明白。由于Django本身不提供静态媒体,并且您必须为其设置apache或类似的东西,所以为什么它不在乎它位于哪个目录中?

What does Django do with MEDIA_ROOT exactly? I never understood it. Since Django itself doesn't serve static media, and you have to set up apache or something similar for it, why does it care in which directory it sits?

推荐答案

您不是唯一一个好奇的人。查看 Django票证#10650 。根据那里的Django开发人员的评论,我认为这几乎总结了 MEDIA_ROOT 的用途:

You're not the only one who wonders; check out Django ticket #10650. Based on the comments by Django developers there, I think this pretty much sums up what MEDIA_ROOT is used for:


不幸的是,Django在其文档中对于
MEDIA_ROOT和MEDIA_URL的用途过于模糊也有过错。通过搜索Django的代码可以确认
MEDIA_ROOT& MEDIA_URL用于文件上传,而MEDIA_URL是通过默认上下文处理器(使用
RequestContext时可用)为模板提供
便利性。

Unfortunately, Django is also at fault for being far too vague in its docs about what MEDIA_ROOT and MEDIA_URL are used for. Searching through Django's code confirms that MEDIA_ROOT & MEDIA_URL are used for file upload, and that MEDIA_URL is provided as a convenience to templates via the default context processors (available when using RequestContext??).

这篇关于Django对`MEDIA_ROOT`有何作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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