I am currently working on a simgle Flask application with React as front end.
(我目前正在使用React作为前端的一个类似Flask应用程序。)
I want to have an elegant way to redirect user to their previous page after they complete the log in process. (在他们完成登录过程后,我想以一种优雅的方式将用户重定向到他们的上一页。)
After some research I figured out using HTTP Referer attribute can work very well like below. (经过一些研究,我发现使用HTTP Referer属性可以很好地工作,如下所示。)
from flask import request
## Massive other code omitted
@app.route(""/login")
def log_in():
return redirect(request.referer)
I am aware that the referer header is added by the browser.
(我知道引荐来源标头是由浏览器添加的。)
The question is, is this a good practice to redirect user back to where they come from using HTTP referer? (问题是,这是将用户重定向回使用HTTP引荐来源网址的一种好习惯吗?)
Any hidden concern of using this approach? (使用这种方法有什么隐忧吗?)
ask by zhaooyue translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…