My goal is to allow users to upload images that are then displayed to all users. The variable "Data" holds the file name (e.g., "files/dog.png"). However, when I try to set the newImg.src value as "{{url_for('static', filename = data )}}", it only turns into "/static/". Below is my code:
var chatDiv = document.getElementById('messages');
const newImg = document.createElement("img");
newImg.src = "{{url_for('static', filename = data )}}";
chatDiv.appendChild(newImg);
I attempted to use Jinja2 string interpolation like this:
newImg.src = "{{url_for('static', filename = data)}}";
But this resulted in an error:
jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}'
Even after removing the brackets, my code still doesn't work. Any help would be greatly appreciated!