Python 请求调用前Flas Restful

Python 请求调用前Flas Restful,python,flask,flask-restful,Python,Flask,Flask Restful,我想用before_request()和tear_down()创建一个API,但有些东西我找不到,我不想重复每个请求。你也可以对一个restful资源对象使用方法装饰器 class Resource(MethodView): """ Represents an abstract RESTful resource. Concrete resources should extend from this class and expose methods for each sup

我想用before_request()和tear_down()创建一个API,但有些东西我找不到,我不想重复每个请求。

你也可以对一个restful
资源
对象使用
方法装饰器

class Resource(MethodView):
    """
    Represents an abstract RESTful resource. Concrete resources should
    extend from this class and expose methods for each supported HTTP
    method. If a resource is invoked with an unsupported HTTP method,
    the API will return a response with status 405 Method Not Allowed.
    Otherwise the appropriate method is called and passed all arguments
    from the url rule used when adding the resource to an Api instance. See
    :meth:`~flask_restful.Api.add_resource` for details.
    """
    representations = None
    method_decorators = []
如果查看源代码,它将按顺序应用装饰程序:

for decorator in self.method_decorators:
    meth = decorator(meth)

resp = meth(*args, **kwargs)

if isinstance(resp, ResponseBase):  # There may be a better way to test
    return resp

representations = self.representations or OrderedDict()

你的问题是什么?只需使用普通的
烧瓶。在请求之前();RESTful在这里什么都不用做。嗨,问题是我已经尝试使用@before_request,但在这样做之后,args字典似乎是空的,所以我不确定我是否遗漏了什么。