I have a project built in React and Django. I am also using Webpack to load the changes. I want to display images from the local drive.
The file from which I want to display the photos is in:
myProject/brandplug/static/app/photoGrid/SampleDisplay.jsx
The photos are located in:
myProject/brandplug/static/location_photos/
The index.jsx
file is in:
myProject/brandplug/static/app/index.jsx
The html
file within which React is rendered is in:
myProject/accounts/templates/index.html
So from SampleDisplay.jsx
I tried importing the images like this:
const itemStyle = {
backgroundImage: `{require("../location_photos/" + ${photoName})}`
};
And then:
<div style={itemStyle}>
</div>
Instead of "../location_photos/"
I also tried using "../../location_photos/"
and "../../brandplug/static/location_photos/"
.
However, the images are still not loaded.
How can I load them?