0👍
Problem is in your image URL,
"image": "/media/None/eeee.PNG",
This should have domain or localhost before /media
on which your Django project is working
Like:
"image": "localhost:8000/media/None/eeee.PNG"
and if you’re running on server this Django project localhost:8000
should replace with domain
So Problem is in your serializer data way, You’re using the wrong way to serialize data because the image URL is not serializing according to your question.
Use a proper Django REST framework serializer to serialize your data.
https://www.django-rest-framework.org/api-guide/serializers/
0👍
Trying to clarfy Neeraj’s answer:
-
instead of sending
"image": "localhost:8000/media/None/eeee.PNG"
-
try:
"image": "http://127.0.0.1:8000/None/eeee.PNG"
Since Django redirects automatically to your media folder. Remember the IP and Port may change depending on your project.
- [Django]-Django migration OperationalError: index [name] already exists
- [Django]-Errors When Installing MySQL-python module for Python 2.7
- [Django]-502 error after adding application to a Django project running on nginx and gunicorn
- [Django]-Django Caching – How do I set up my code to avoid duplicating cache logic?
- [Django]-Django-mptt filter without breaking the tree
- [Django]-Prefetch_related() join all on first item
0👍
This how I did mine, this solution works if anyone still having issues with this same question.
class Image(models.Model):
image_file = models.ImageField()
@property
def get_image_url(self) -> str:
if self.image_file and hasattr(self.image_file, 'url'):
return f"http://localhost:8000{self.image_file.url"
```.
Image_file is the image file in the model class and the property function also belong to the same class. So knsdI hope this helps because it work for me.
- [Django]-Hosting Admin Media Locally During Development
- [Django]-Django on Aptana Studio 3.0
- [Django]-Django Serializer returns JSON for parent class objects only and leave child objects as same?
- [Django]-Django: how to map the results of a raw sql query to model instances in admin list view?
- [Django]-Passing Editable Fields as validated_data method of Django-Rest-Framework Serializer