Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript document.write图像错误_Javascript_Html_Flask_Document.write - Fatal编程技术网

javascript document.write图像错误

javascript document.write图像错误,javascript,html,flask,document.write,Javascript,Html,Flask,Document.write,我使用Flask并将变量(image_name)传递给javascript以获取动态web内容。 我在document.write()中使用这些变量来显示图像文件。 根据变量image_name,应加载所需的.jpg文件 这是我的JS代码: document.write('<img class="img-circle profile_img" ' + 'src="{{ url_for(' + "'static', filename='images/" + "'{{ image_name }

我使用Flask并将变量(image_name)传递给javascript以获取动态web内容。 我在document.write()中使用这些变量来显示图像文件。 根据变量image_name,应加载所需的.jpg文件

这是我的JS代码:

document.write('<img class="img-circle profile_img" '
+ 'src="{{ url_for(' + "'static', filename='images/"
+ "'{{ image_name }}'" + ".jpg' )}}"
+ '" onerror="'
+ "this.onerror=null;this.src='../static/images/"
+ "'{{ image_name }}'"
+ ".jpg';"+'"'+"/>");
document.write(“”);
使用image\u name=“max\u mustermann”时,我希望输出为:

<img class="img-circle profile_img" src="{{ url_for('static', filename='images/max_mustermann.jpg' )}}" onerror="this.onerror=null;this.src='../static/images/max_mustermann.jpg';"/>

当我运行Flask并尝试加载页面时,我的浏览器显示以下错误

jinja2.exceptions.TemplateSyntaxError:应为标记“,”,已获取 “静态”


你能详细说明一下你到底想要实现什么吗?无论你在做什么,这都不是正确的方法。引号至少有一个问题:你把图像名称放在单引号中。可能是重复的谢谢!问题是我在{{}中使用了{{}。