models
image_url = models.ImageField(upload_to="uploads/shows",blank=True,null=True)
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).
I have tried
image_url=myObj.file.url
image_url=myObj.image_url
The location of the uploaded image will be in MEDIA_ROOT/images . In Django, the MEDIA_ROOT setting is where we define the location of all user uploaded items.
By default, Django stores files locally, using the MEDIA_ROOT and MEDIA_URL settings. The examples below assume that you're using these defaults. However, Django provides ways to write custom file storage systems that allow you to completely customize where and how Django stores files.
You can obtain such name with os. path. splitext [Python-doc] to split a filename in the "root" and the "extension".
The correct working solution as provided by @alecxe is
image_url =myObj.image_url.url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With