Run code after flask application has started

后端 未结 6 929
渐次进展
渐次进展 2020-12-09 14:54

My goal is to get arbitrary code to run after my Flask application is started. Here is what I\'ve got:

def run():
    from webapp import app
    app.run(debu         


        
6条回答
  •  误落风尘
    2020-12-09 15:05

    Use Flask-Script to run your app, then overwrite the runserver class/method like this

    # manage.py
    
    from flask.ext.script import Manager
    
    from myapp import app
    
    manager = Manager(app)
    
    def crazy_call():
        print("crazy_call")
    
    @manager.command
    def runserver():
        app.run()
        crazy_call()
    
    if __name__ == "__main__":
        manager.run()
    

提交回复
热议问题