如何组合带参数的装饰器?
目前我有:
@app.route('/create/<id>', methods=['POST'])
@requiresAdmin
def create_room(id):
pass
@app.route('/join/<id>')
@requiresAdmin
def join_room(id):
pass
我想:
@adminRoute('/create/<id>', methods=['POST'])
def create_room(id):
pass
@adminRoute('/join/<id>')
def join_room(id):
pass
答案 0 :(得分:0)
def adminRoute(*route_args, **route_kwargs):
def outer(action_function):
@app.route(*route_args, **route_kwargs)
@requiresAdmin
@functools.wraps(action_function)
def inner(*f_args, **f_kwargs):
return action_function(f_args, f_kwargs)
return inner
return outer