沃梦达 / IT编程 / 前端开发 / 正文

flask and html connection

pythonfrom flask import Flask, render_templatefrom eas_prediction import PredictClientfrom eas_prediction import StringRequestapp = Flask(testapp)@app.route(/)def index():#下面的client = Predi...

python

from flask import Flask, render_template
from eas_prediction import PredictClient
from eas_prediction import StringRequest

app = Flask('testapp')

@app.route('/')
def index():
    #下面的client = PredictClient()入参源于公网调用的访问地址。
    client = PredictClient('http://1875193938847529.cn-shanghai.pai-eas.aliyuncs.com','dequn_teng_fyp')
    #Token可以在公网地址调用信息中获取,详情请参见通用公网调用部分。
    client.set_token('OTMwNmEwNmFkYjM2Y2RlMjAzM2RkMzc3NWQ0Mzc2OGMxZTRiNzM3Zg==')
    client.init()
    #输入请求需要根据模型进行构造,此处仅以字符串作为输入输出的程序为例。
    request = StringRequest('[{"item_buy_rate":0,"user_buy_rate":0}]')
    for x in range(0, 1):
        resp = client.predict(request)

    return render_template('index.html', variable=resp)
if __name__ == '__main__':

    app.run()


HTML


<html>
<body>
    <p>Here is my variable: {{ variable }}</p>
</body>
</html>

本文标题为:flask and html connection