Python 类型错误:';会议';对象不支持项分配
我使用Flask会话来确定是否有人登录到某个站点,但当我尝试为其赋值时,它返回错误“TypeError:“Session”对象不支持项赋值”Python 类型错误:';会议';对象不支持项分配,python,flask,flask-session,Python,Flask,Flask Session,我使用Flask会话来确定是否有人登录到某个站点,但当我尝试为其赋值时,它返回错误“TypeError:“Session”对象不支持项赋值” 谢谢你的帮助 您可以使用此示例 @app.route("/login",methods = ["POST","GET"]) def login(): if request.method == "POST": try: Email = request.form
谢谢你的帮助 您可以使用此示例
@app.route("/login",methods = ["POST","GET"])
def login():
if request.method == "POST":
try:
Email = request.form["email"]
pwd = request.form["pwd"]
with sqlite3.connect("Account.db") as con:
cur = con.cursor()
print("Connection test")
cur.execute("SELECT * FROM Account WHERE Email= ? and Password= ?",(Email, pwd))
row = cur.fetchone()
print("query test")
while row is not None:
session['email']=request.form['email']
print(row[1])
return render_template("success.html",msg = msg)
else:
msg = "sorry wrong id"
return render_template("failure.html",msg = msg)
except:
con.rollback()
msg = "problem"
然后在另一个函数中
if 'email' in session:
email = session['email']
return render_template("view.html")
else:
return '<p>Please login first</p>'
如果会话中出现“电子邮件”:
电子邮件=会话['email']
返回渲染模板(“view.html”)
其他:
返回“请先登录”
如果您正在使用flask,您可以使用我提供的代码
if 'email' in session:
email = session['email']
return render_template("view.html")
else:
return '<p>Please login first</p>'