考虑到这一点,我已经看到了很多问题,但未能解决我的问题.我有一个带烧瓶登录的Flask应用程序用于会话管理.而且,当我尝试在没有登录的情况下查看页面时,我会被重定向到一个形式的链接/login/?next=%2Fsettings%2F
问题是,据我所知,"下一个"参数保存了我实际需要的网站部分,但是当向登录表单提交请求时,它是通过完成的POST,所以这个论点不再存在可供我重定向到.
我试图使用Request.path从申请(网址),但都只是返回/login/的请求URL /路径,而不是实际的/login/?next=xxx.
我的登录方法如下:
@app.route('/login/', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
#getting the user
user = User.get(request.form['username'])
if user.user is None:
return redirect('/login/')
#actual login proces
if user and check_password_hash(user.user.password, request.form['password']):
login_user(user, remember=remember)
#the redirection portion of the login process
return redirect(request.path or ("/")) # I tried various options there but without success, like request.args['next'] and such
return redirect('/login/')
else:
return redirect('/')
Run Code Online (Sandbox Code Playgroud)
谢谢