So as stated, I'm having trouble loading images from Django backend(fetch works fine). I've looked other similar questions, but NONE OF THEM HELPED, sadly.
So here's my Django code:
settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
model.py
class Content(models.Model):
objects = models.Manager()
image = models.ImageField(upload_to='None', height_field=None, width_field=None, max_length=None, null=True, blank=True)
key_line = models.CharField(max_length = 100, null=True)
body = models.TextField(blank=True, null=True)
I've uploaded an image named 'eeee.PNG' via admin, and I can see the data serialized in JSON format like below:
[
{
"id": 5,
"image": "/media/None/eeee.PNG",
"key_line": "key.",
"body": "blablabla",
},
]
And my React code (fetch has been successfully worked) :
<Container classname="">
<Row className="">
<Col className="text-text img-eachcake">{this.props.image}</Col>
<Col className="text-text img-eachcake" src={this.props.image}></Col>
</Row>
</Container>
As you can see, I've tried two ways but none of them worked. What do you think is the problem? All the other props are loaded fine. It's just the image file that doesn't work.
+in the inspection mode > Elements, I see the line as : <div src="/media/None/eeee.PNG" class="text-text img-eachcake col"></div>