我正在使用 Flask-Session 来确定天气是否有人登录到站点,但是当我尝试为其分配值时,它返回错误“TypeError:'Session' 对象不支持项目分配”。
@app.route("/login", methods=["POST", "GET"])
def login():
if request.method == "POST":
username = request.form["gets username input"]
password = request.form["gets password input"]
allowed = db.execute(SQL for checking if the username and password are in the SQL db)
allowed = allowed.first()[0]
if allowed == 1:
loginsession = Session()
id = db.execute(SQL for finding the id of the user)
loginsession["id"] = id
print(loginsession["id"])
return redirect(url_for("the route to the profile page"))
else:
return "Incorrect username or password"
else:
return render_template("login.html")
谢谢你的帮助!