django获取FileField的绝对路径 [英] django getting the absolute path of a FileField
本文介绍了django获取FileField的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何实现这一点?
我正在尝试从模板中调用FileField来检索绝对路径(以http://开头) p>
ie:
{{fl.uploadedfile}}
- >返回相对路径,如media / uploads /
,而我要此
cheers
解决方案
Django File对象提供了几个方便的功能/属性,其中之一是与该文件相关联的URL。在这种情况下,正如您所指出的,您正在寻找 url
属性。
I am trying to retrieve the absolute path (starting with http://) while calling a FileField at the template.
How can I achieve this ?
ie:
{{fl.uploadedfile}}
-> returns relative path like media/uploads/
while I want This
Cheers
解决方案
The Django File object provides several convenience functions/attributes, one of which is the URL associated with the file. In this case, as you pointed out, you're looking for the url
attribute.
这篇关于django获取FileField的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文