我有一个简单的烧瓶终点来做到这一点
src = 'src=\"https://www.google.com/maps/embed/v1/directions?key=' + googleAPIkey + '&origin=' + location + '&destination=' + dest + '\"'
return render_template('map.html',link = src)
如果我的模板是这样的话,这段代码工作正常
<iframe
width="800"
height="600"
frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/directions?key=AIzaSyAZ5styOuSR9i0VuS7FXTyHU2dPWDXQcm0&origin=mirpur& destination=gulshan" allowfullscreen>
</iframe>
但是,当我像这样替换src字段时,它显示404找不到错误:
<iframe
width="800"
height="600"
frameborder="0" style="border:0"
{{link}} allowfullscreen>
</iframe>
我检查了链接参数是否正确发送,因为如果我将{{link}}放在我的模板中,它就会正确打印。但是,出于某种原因,它在iframe的src字段中不起作用。谁能说出原因?
更改
src = 'src=\"https://www.google.com/maps/embed/v1/directions?key=' + googleAPIkey + '&origin=' + location + '&destination=' + dest + '\"'
return render_template('map.html',link = src)
至
src = "https://www.google.com/maps/embed/v1/directions?key={api_key}&origin={location}&destination={dest}".format(api_key=googleAPIkey, location=location, dest=dest)
return render_template('map.html', link=src)
并替换
<iframe
width="800"
height="600"
frameborder="0" style="border:0"
{{link}} allowfullscreen>
</iframe>
通过
<iframe
width="800"
height="600"
frameborder="0" style="border:0"
src={{link}}
allowfullscreen>
</iframe>
这应该工作。