Dataframe 如何使用Flask decorator@app.after\u请求将熊猫数据框转换为html或字符串

Dataframe 如何使用Flask decorator@app.after\u请求将熊猫数据框转换为html或字符串,dataframe,flask,Dataframe,Flask,我希望使Flask能够使用数据帧进行响应。我宁愿截取数据帧并调用.to\u html()inside@app.after请求,而不是用.to\u html()将我的函数代码弄乱,如下所示 @app.after_request def after_request_func(response): logging.info("after_request") if hasattr(response, 'to_html'): return respons

我希望使Flask能够使用数据帧进行响应。我宁愿截取数据帧并调用
.to\u html()
inside@app.after请求,而不是用
.to\u html()
将我的函数代码弄乱,如下所示

@app.after_request
def after_request_func(response):
    logging.info("after_request")
    if hasattr(response, 'to_html'):
        return response.to_html()

    return response
不幸的是我

TypeError:view函数未返回有效响应。这个 返回类型必须是字符串、dict、元组、响应实例或WSGI 可调用,但它是一个数据帧

这种不良行为意味着@app.after_请求实际上是@app.after_响应

我想我可能会把@app.route()函数弄得乱七八糟
请求后返回功能(df)

如果有人知道更清洁的解决方案,请分享