django程序,需要写很多api,每个函数都需要几个装饰器,例如
@csrf_exempt @require_POST def foo(request): pass
csrf_exempt(require_POST(foo))
def compose(*funs): def deco(f): for fun in reversed(funs): f = fun(f) return f return deco
@compose(csrf_exempt, require_POST) def foo(request): pass
参考:
Can I combine two decorators into a single one in Python