我想显示来自请求https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-nav的数据'在我的网络应用程序上我希望这个数据在我的应用程序上更新,让我们说每3秒钟。我正在使用flask 3.6和python 3.6。我的flask.py文件:
from flask import Flask, render_template, request
import requests
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def price():
url='https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-nav'
z=[]
r = requests.get(url)
x=r.json()
e1=x['result'][0]['Ask']
e2=x['result'][0]['Bid']
z.append(e1)
z.append(e2)
#print("TEMPLATE_FOLDER = {}".format(app.template_folder))
return render_template('templ.html', data=z ,template_folder='/home/...templates/')
if __name__ == '__main__':
app.run(debug=True)
这是我的templ.html:
<!DOCTYPE html>
<html>
<head>
<title>Suggestions</title>
</head>
<body>
Search: <input type="text" id="search_form_input"></input>
<div id="place_for_suggestions"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$("#search_form_input").keyup(function(){
var text = $(this).val();
$.ajax({
url: "/",
type: "get",
data: <label id="value_lable">
{% for i in data %}
{{ i }}<br>
{% endfor %}
</label>,
success: function(response) {
$("#place_for_suggestions").html(response);
},
error: function(xhr) {
//Do Something to handle error
}
});
});
</script>
</body>
</html>
我的网站没有货币价格数据 - http://weblanss.pythonanywhere.com//
我是新的烧瓶,请帮助我。如何在我的网站上显示请求中的数据?如何每3秒更新一次?