Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Get ImageField Path

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
like image 504
onkar Avatar asked Sep 11 '13 12:09

onkar


People also ask

How can I get image path in Django?

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.

Where does Django store files?

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.

How can I get image name in Django?

You can obtain such name with os. path. splitext [Python-doc] to split a filename in the "root" and the "extension".


1 Answers

The correct working solution as provided by @alecxe is

image_url =myObj.image_url.url
like image 132
onkar Avatar answered Sep 18 '22 21:09

onkar