decorators.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:django-express 作者: bluekvirus 项目源码 文件源码
def service(func):
    """
    Make sure this is the first/closest @wrapper on your service function

    Note that this decorator tags the original function with meta and new arguments.
    The real url-->fn() registeration happens in __init__.py autodiscover() because of @url.
    """
    @csrf_exempt  # setting wrapper.csrf_exempt = True, consulted by CsrfViewMiddleware
    def wrapper(req, *args, **kwargs):
        response = ExpressResponse()
        request = ExpressRequest(req)
        func(request, response, *args, **kwargs)  # all service functions should have this signature.
        return response._res
    wrapper.__name__ = func.__name__
    wrapper.__doc__ = func.__doc__
    wrapper.__module__ = func.__module__
    # base entrypoint
    wrapper._path = func.__name__
    return wrapper


# use only on a Django ORM Model cls
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号