标签:python 装饰器 meger decorator 合并
django程序,需要写很多api,每个函数都需要几个装饰器,例如@csrf_exempt
@require_POST
def  foo(request):
    passcsrf_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
本文出自 “orangleliu笔记本” 博客,转载请务必保留此出处http://blog.csdn.net/orangleliu/article/details/43308397
作者orangleliu 采用署名-非商业性使用-相同方式共享协议
标签:python 装饰器 meger decorator 合并
原文地址:http://blog.csdn.net/orangleliu/article/details/43308397