Django - MEDIA_ROOT 和 MEDIA_URL [英] Django - MEDIA_ROOT and MEDIA_URL

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

问题描述

能否请您推荐我可以理解 MEDIA_URL 和 MEDIA_ROOT 的好文档?这真的让我很困惑.

Could you please suggest me the good documentation where I can understand the MEDIA_URL and MEDIA_ROOT? It's really confusing me.

推荐答案

MEDIA_ROOT文件系统上到包含静态媒体的目录的路径.

The MEDIA_ROOT is the path on the filesystem to the directory containing your static media.

MEDIA_URL 是使静态媒体可通过 HTTP 访问的 URL.

The MEDIA_URL is the URL that makes the static media accessible over HTTP.

文档:http://docs.djangoproject.com/en/1.2/ref/settings/#media-root

主要思想是通过 python+django 提供服务是昂贵的.由于您的媒体是静态的,因此您无需支付该费用,因此您可以采用不同的方式为其提供服务(例如,直接通过 nginx 或通过 CDN).但是,您仍然需要知道媒体在文件系统中的位置(例如用于文件上传)以及 URL 是什么(例如放入模板).存在的设置将所有这些联系在一起.

The main idea is that serving things through python+django is expensive. Since your media is static you don't need to pay that cost, so you serve it differently (e.g. directly via nginx or through a CDN). However, you still need to know where the media is located in the file system (e.g. for file uploads) and what the URL is (e.g. to put in templates). The settings exist to tie all that together.

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

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