我有很多线程的应用程序。其中一个是烧瓶,用于实现(腋窝)API。它使用低负载,从不暴露在互联网上,所以内置flask web服务器是完美的。
我当前的代码如下:
class API:
# ... all other stuff here, skipped
def run():
app = flask.Flask('API')
@app.route('/cmd1')
def cmd1():
self.cmd1()
@app.route('/cmd2')
def cmd2()
self.cmd2()
app.run()
我觉得我做错了,因为所有的文档都说“在模块级创建烧瓶应用程序”。但我不想这样做-这会扰乱我的测试,而且API是大型应用程序的一小部分,它有自己的结构和协议(每个“应用程序”是在一个或多个线程中运行的独立类)。
我怎样才能在课堂上使用烧瓶?
虽然这样做,但感觉不符合烧瓶样式指南。如果需要在项目中包装Flask应用程序,请根据需要创建一个单独的类,并添加应执行的函数
这里需要注意的是:
EndpointAction
应该是一个包装器,它将执行您的函数并生成一个空的200响应。如果需要,可以编辑功能__call__
方法的对象为了完成Kostas pellelis的回答,因为我很难找到为什么响应没有直接使用操作返回值。
下面是另一个没有decorators的FLASK类:
相关问题 更多 >
编程相关推荐