[Answered ]-Django Rest Framework – do not return url if imagefield doesnt exist

2👍

Calling .url raises an exception if obj.image is None.

You can update get_image_url as follows:

def get_image_url(self, obj):
    if obj.image:
        return obj.image.url
    else:
        return None

Leave a comment