flask 多线程 使用数据库报错 No application found. Either work inside a view function or push an application context.

 

 

https://www.cnblogs.com/lutt/p/15969649.html

 

 

def sqlalchemy_context():
    def add_context(func):
        @wraps(func)
        def do_job(*args, **kwargs):
            # app.app_context().push()
            from app import app
            with app.app_context():
                result = func(*args,**kwargs)
                return result
        return do_job
    return add_context


@sqlalchemy_context()
def go():

    pass

 

 

posted @ 2022-10-11 15:57  AngDH  阅读(60)  评论(0编辑  收藏  举报