django getting the absolute path of a FileField

大城市里の小女人 提交于 2019-12-05 12:46:51

问题


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


回答1:


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.




回答2:


Just found the answer: adding .url fixes this issue fixes it such as {{fl.uploadedfile.url}}



来源:https://stackoverflow.com/questions/1211527/django-getting-the-absolute-path-of-a-filefield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!