【发布时间】:2019-03-15 21:10:07
【问题描述】:
我制作了一个烧瓶应用程序,它依赖于会话 cookie 进行登录。但是,每当我重新打开浏览器并访问 http://localhost:5000/ 时,cookie 就会消失并且我已注销。
这是我的一些代码:
app = Flask(__name__)
app.config["SECRET_KEY"] = <bytes object generated by os.urandom(24)>
app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(hours=1)
@app.route("/")
def login_redirect():
if check_login(session, False):
return redirect("/interface")
return redirect("/login")
def check_login(session, requires_elevated):
if "username" not in session:
return False
elif session["username"] == "admin":
return True
elif session["username"] == "regular" and not requires_elevated:
return True
return False
我不想粘贴所有内容,因为如果它是私人的,但如果我可以包含其他任何可能有帮助的内容,请告诉我,我会这样做。
谢谢。
【问题讨论】: