Python Flask render_模板用于发送iframe的参数时显示错误
我有一个简单的烧瓶端点来实现这一点Python Flask render_模板用于发送iframe的参数时显示错误,python,flask,Python,Flask,我有一个简单的烧瓶端点来实现这一点 src = 'src=\"https://www.google.com/maps/embed/v1/directions?key=' + googleAPIkey + '&origin=' + location + '&destination=' + dest + '\"' return render_template('map.html',link = src) 如果我的模板是以下内容,则此代码可以正常工作: <ifr
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 not found错误:
<iframe
width="800"
height="600"
frameborder="0" style="border:0"
{{link}} allowfullscreen>
</iframe>
如果我在模板中放入{{link},我检查了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)
到
替换
<iframe
width="800"
height="600"
frameborder="0" style="border:0"
{{link}} allowfullscreen>
</iframe>
借
这应该是可行的。Flask的
render\u模板
清理HTML呈现的输入,这可能会将您的“
更改为”
。尝试将Python代码更改为只包含URL,然后将模板更改为src=“{{link}”
@Jan Gerd谢谢,它成功了
<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>