首页 > 解决方案 > 从 mongo 获取数据时对函数应用限制

问题描述

有一个具有 m 个 API 的 python 代码,它获取具有 n 个字段的请求模式并从 mongoDB 获取响应

我想写一个装饰器来限制来自 mongo 的响应

例如:

从 API 之一,如果请求模式中有 7 个字段并且预期字段为 2,即 id 和状态。2 个字段可处理的最大条目数为 250

装修师应该怎么做?

对装饰器一无所知。请建议

    def decorator(func):
        func = validate_parameters(request_schema)(func)
        func = parse_query_parameters(request_schema)(func)
        func = returns_json(func)
        if requires_authentication:
            func = jwt_required(func)
        endpoint = str(uuid4())
        for route in routes:
            blueprint.route(route, methods=methods, endpoint=endpoint)(func)
        flex_schema_by_endpoint[endpoint] = dict(request=request_schema, response=response_schema,
                                             exceptions=exceptions,   requires_authentication=requires_authentication)
         return func

标签: pythonmongodbpymongopython-decorators

解决方案


推荐阅读