【发布时间】:2021-09-20 01:13:44
【问题描述】:
from flask import Flask, session, request, render_template
import model //model.py
app = Flask(_name__)
session.key = "randomkey"
@app.route("/", methods = ['POST', 'GET'])
def hello():
if request.method == 'POST':
//Some cide that takes input from index.html and stores in python variables
prediction = model.make_prediction(modelinput)
session["prediction"] = prediction
return render_template("index.html")
@app.route("/prediction", methods = ['POST', 'GET'])
def submit():
final_prediction = session.get("prediction", None)
return render_template("prediction.html", predic = final_prediction)
现在,即使我使用会话变量在会话之间传递值,我也会得到一个 None 值作为输出。这是为什么呢?
【问题讨论】:
-
我在我的系统上运行了你的代码,没有数据库,它工作正常。检查
prediction = model.make_prediction(modelinput)这一行是否给出了所需的输出。 -
是的,该行给出了所需的输出。我通过使用 print 函数在终端中打印变量进行了验证。