【发布时间】:2014-08-06 16:25:34
【问题描述】:
def check_login(func):
"""Check if user is logged in."""
def decorator(*args, **kwargs):
if not login_session_test():
print ("Not logged in - redirect to /login")
flash ("Well that was wrong. Chicken winner. No more dinner.")
return redirect(url_for('login'))
print ("Logged in, do what needs to be done.")
return func(*args, **kwargs)
return decorator
@check_login
@app.route("/sacred/secret/stuff", methods=['GET'])
def funfunfun():
return "Super fun"
它永远不会重定向到/login,但会给出一些垃圾页面。
交换@/closure 订单产生:
AssertionError: View function mapping is overwriting an existing endpoint function: decorator
我还没有完全 Python 化。
【问题讨论】:
标签: redirect python-3.x flask closures