What's the right approach for calling functions after a flask app is run?

后端 未结 3 1237
孤城傲影
孤城傲影 2020-12-08 09:56

I\'m a little confused about how to do something that I thought would be quite simple. I have a simple app written using Flask. It looks something like this:

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 10:25

    from flask import Flask
    
    def create_app():
        app = Flask(__name__)
        def run_on_start(*args, **argv):
            print "function before start"
        run_on_start()
        return app
    
    app = create_app()
    
    @app.route("/")
    def hello():
        return "Hello World!"
    

提交回复
热议问题