I'm following this tutorial series on youtube and I'm near the end of the first video but have run into some difficulties.
The code can be found here.
Basically the admin page allows the user to create a dummy item with an image. This image is saved with a path of the server IP and the image name. 127.0.0.1/media/image.type
It successfully stores it into the media folder. But when I try to use this stored image on the client side with {item.image}
it uses the server IP and image name. But on the client side for some reason, it doesn't grab the image file. Instead only '/media/image.type'
seems to successfully get the file.
This seems like a problem because when the website goes live I would need to use a server IP for accessing and storing the image. Otherwise, I'd use a regex or string trim to get rid of the IP part of the image source to get it to work.
Pretty sure my media folder is set up correctly.
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'build/static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
My Image call inside ProductList.js
<Item.Group divided>
{data.map(item => {
return ( <Item key={item.id}>
<Item.Image src={item.image}/>
<Item.Content>
<Item.Header as='a'>{item.title}</Item.Header>
<Item.Meta>
<span className='cinema'>{item.category}</span>
</Item.Meta>
<Item.Description>{item.description}</Item.Description>
<Item.Extra>
<Button primary floated='right' icon labelPosition="right">
Add to Cart
<Icon name='cart plus'/>
</Button>
{item.discount_price && <Label>{item.label}</Label>}
</Item.Extra>
</Item.Content>
</Item>
);
})}
</Item.Group>
Printing of image details to console: