def make_proxy_method(cls, name):
"""
Creates a proxy function that can be used by Flasks routing. The
proxy instantiates the FlaskView subclass and calls the appropriate
method.
:param name: the name of the method to create a proxy for
"""
i = cls()
view = getattr(i, name)
if cls.__decorators__:
for decorator in cls.__decorators__:
view = decorator(view)
@functools.wraps(view)
def proxy(**forgettable_view_args):
# Always use the global request object's view_args, because they
# can be modified by intervening function before an endpoint or
# wrapper gets called. This matches Flask's behavior.
del forgettable_view_args
response = view(**request.view_args)
if not isinstance(response, Response):
response = make_response(response)
return response
return proxy
评论列表
文章目录