In the before_request()
function (below), I want to redirect the user to /login
if they are not yet logged in. Is there a special variable that will give me the current URL that will work as the below example does?
@app.before_request
def before_request():
# the variable current_url does not exist
# but i want something that works like it
if (not 'logged_in' in session) and (current_url != '/login'):
return redirect(url_for('login'))
I need to check that the current URL is /login
, because if I don't the server goes into an infinite loop.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…