如果 Flask 应用程序中存在活动会话,如何跳过登录页面
目前我有 Flask 应用程序,在成功登录后,我将页面重定向到索引 -
http://example.com/ --> 登录后 --> http://example.com/index(成功)
但是,当活动会话存在时,当我尝试 http://example.com/ 时,我会再次进入登录页面。
在您的登录处理程序中,只需检查用户是否在函数的早期登录。例如,如果您使用 Flask-Login:
def login():
if current_user.is_authenticated():
return redirect(url_for('index'))
# process login for anon user