Is there any update on image field serializer? I was trying to server an image api to the frontend. My serializer is not returning image link instead its returning the path relative to the base dir of the django-project
models.py
def upload_to(instance, filename):
return 'profiles/{filename}'.format(filename=filename)
class Picture(models.Model):
image = models.ImageField(upload_to=upload_to)
serializer
class PictureSerializer(serializers.ModelSerializer):
class Meta:
model = Picture
fields = ['image']
**serializer.data result **
[
{
"image": "/media/profiles/quiz-app-.jpg"
},
{
"image": "/media/profiles/coding2.jpg"
},
{
"image": "/media/profiles/dummy_2s9CyV8.jpg"
}
]
instead of the above result I want something like a link in return
[
{
"image": "http://127.0.0.1:8000/api/media/profiles/quiz-app-.jpg"
},
{
"image": "http://127.0.0.1:8000/api/media/profiles/coding2.jpg"
},
{
"image": "http://127.0.0.1:8000/api/media/profiles/dummy_2s9CyV8.jpg"
}
]