Answer the question
In order to leave comments, you need to log in
How to give image url to drf as link to image?
I have already asked this question before, but apparently either I myself understand everything very poorly, or I don’t ask at all like that. You need to give the image in the / media folder so that it can be inserted as <img src="https://media/my_img.jpeg">
in html on the client side. The Django Rest Framework has the ability to create serialization classes, but they require additional logic to be written in views.py. Is there a way to specify the path to the image from the file system inside the json object without adding unnecessary logic to views?
Thank you!
UPD:
json is returned like this:
return JsonResponse({
'id': menu.id,
'name': menu.name,
'img': os.path.join(MEDIA_ROOT, menu.img.url)
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question