I'm working on a d3 based visualization tool that allows users to click paths on images. That works all fine until I tried to let the user change the background image by a simple dropdown.
The problem was that javascript can not load files from the disk since to Cross-Origin permissions. So the solution I picked was to set up a backend. I choose Django.
This is the javascript code which manipulates the image:
window.LOADED_FILE = "PUT PATH HERE";
I have a working dropdown where the user can pick an image and I get then the path to the file. After this, I tried to load the image like the following.
window.SVG.append("image")
.attr("width", window.WIDTH + "px")
.attr("height", window.HEIGHT + "px")
.attr("xlink:href", window.LOADED_FILE);
This doesn't work at all and I only get a placeholder image for the 404 Request. So tried to following two things:
First of all, this is a solution that I found here. This works fine, but I don't want and I cant hardcode every possible image into an HTML file just to pick the correct variable when the user wants to select another image them later when the user wants. So I need a more dynamic solution.
After this, I tried the following. But when I do
console.log(DJANGO_STATIC_URL)
I get a an empty log. In the settings.py file contains the following static url:STATIC_URL = '/static/'
.
So what I want is a solution on how I should load images with javascript without hardcoding them in before in an HTML file. I suspect that I have misunderstood something or ignored something obvious.