Python中Flask iframe加载时碰到奇怪问题如何解决

我想在一个 Flask 项目里面嵌入实时股票 Chart,在网上找到 Investing.com 以 iframe 方式提供这种 widget https://www.investing.com/webmaster-tools/technical-charts

于是,我随便生成一个 QQQ 的 k 线图,Investing 给我的代码如下:

<iframe height="800" width="600" src="https://ssltvc.forexprostools.com/?pair_ID=651&height=800&width=600&interval=86400&plotStyle=candles&domain_ID=1&lang_ID=1&timezone_ID=7"></iframe>

我把这个代码随便嵌到一个网站里面没问题,比如: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe 这个里面替换 iframe,可以正确显示。

flask 代码在本地跑的时候,以 127.0.0.1 跑,显示域名不对,于是我换成 localhost,可以显示。但是显然我这个程序是需要跑在服务器上的。我把代码拷贝到云主机,在云主机里面跑的时候,显示 504 Gateway Error, 但是单独把 src 输入地址栏又可以打开。会是什么问题呢?

把 src 换成 baidu,google 之类的,也没问题。

Flask 代码如下:

from flask import Flask, render_template

app = Flask(name)

@app.route("/") def Index(): return render_template(‘index.html’)

app.run(‘0.0.0.0’, 80)

template/index.html 代码如下:

<html>
  <head><title>Test</title></head>
<body>

<div> <iframe height=“800” width=“600” src=“https://ssltvc.forexprostools.com/?pair_ID=651&height=800&width=600&interval=86400&plotStyle=candles&domain_ID=1&lang_ID=1&timezone_ID=7”></iframe> </div>

</body> </html>


Python中Flask iframe加载时碰到奇怪问题如何解决

16 回复

有人能解决吗, ¥666 外包


我无法理解你的问题。

用这个

是不是因为模版文件没有放在 templates 目录下?

谢谢,我测试一下先,因为我要复用,会经常修改 pair_id,不知道里面其他参数是否能复用,比如 carrier, 等,我先试下。。。

在 templates 下面

麻烦发我你的支付宝账号,我给你转账。

你这个 src 是怎么得到的?我之前在本机上跟踪浏览器的调用,没有访问 cdn,另外,请问 carrier 从哪里得? time 应该就是一个 timestamp 吧。不知道能复用多久。

Please complete payee’s name [ ] shi xiang ? 姓?

右键查看 “页面源代码”

Received. Thank you!

回头不能用了找你售后,哈哈。加我微信 cTQwNTAxOA==

另外,可以从 iframe 那边解决吗? 否者感觉需要自己 request,取这些参数再修改内容。很麻烦。

iframe 这个我看下,wechat 已加

回到顶部