ここに示すデコレーターを使用して、自分のニーズに合わせました (複数のロール) デコレーターはロールをチェックし、権限がないかどうかを通知しますが、元のデコレーターのようにログイン ページにリダイレクトしません。
def login_required(role="ANY"):
def wrapper(fn):
@wraps(fn)
def decorated_view(*args, **kwargs):
if not current_user.is_authenticated():
return lm.unauthorized()
if ((role not in current_user.roles) and (role != "ANY")):
return lm.unauthorized()
return fn(*args, **kwargs)
return decorated_view
return wrapper
ここにフラスコログインの元のデコレータがあります:
def login_required(func):
@wraps(func)
def decorated_view(*args, **kwargs):
if current_app.login_manager._login_disabled:
return func(*args, **kwargs)
elif not current_user.is_authenticated():
return current_app.login_manager.unauthorized()
return func(*args, **kwargs)
return decorated_view