Django 获取 ImageField 路径 [英] Django Get ImageField Path

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

问题描述

模型

image_url = models.ImageField(upload_to="uploads/shows",blank=True,null=True)

我有 image_url,我需要使用 JSON 对象将其解析到我的 android 应用程序.我只需要图片的网址(绝对/相对).

I am having image_url which I need to parse it using JSON object to my android application. I only need the URL of the image(absolute/relative).

我试过了

image_url=myObj.file.url
image_url=myObj.image_url

推荐答案

@alecxe 提供的正确工作解决方案是

The correct working solution as provided by @alecxe is

image_url =myObj.image_url.url

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

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