【发布时间】:2018-09-07 06:12:34
【问题描述】:
我目前正在为 python/flask/Jquery 苦苦挣扎!
我想在img标签中使用URL_for函数,但是在使用的时候,浏览器做出了奇怪的事情!
$("div.left").append("<img id='my_img' class='centered' style='width:100%; height:100%' src=" + "{{ url_for('static', filename='./img/logo.png') }}" + "alt='Loading error!' />")
这是浏览器给我的:
<img id="my_img" class="centered" style="width:100%; height:100%" src="/static/img/logo.pngalt='Loading" error!'="">
最后一个问题:是否可以将代码放在带有 url_for 的 js 文件中(似乎不适合我!)?
【问题讨论】:
-
我认为问题在于使用单引号和双引号。最好将
{{ url_for('static', filename='./img/logo.png') }}保存在单独的变量中并连接起来。
标签: javascript python jquery html flask