Django: Get ImageField url in view Django: Get ImageField url in view django django

Django: Get ImageField url in view


When configured correctly, use .url: item.image.url. Check the docs here.


Maybe this way?

@propertydef get_absolute_image_url(self):    return "{0}{1}".format(settings.MEDIA_URL, self.image.url)

see How can I get a list of absolute image URLs from a Django QuerySet?


I just figured out what was the problem... absolute image path is saved in file variable.

Example (in view):

item = Item.objects.get(pk=1)print item.file # prints out full path of image (saved in media folder)