Skip to content Skip to sidebar Skip to footer

How To Run Function Before Flask Routing Is Starting?

I need to do call function before Flask routing is starting working. Where I should to put function to make it called at service start. I did: app = Flask(__name__) def checkIfDBEx

Solution 1:

If i were you, I'd put it in a function creating an app, like:

def checkIfDBExists(): # it is my function
    ifnot DBFullPath.exists():
         print("Local DB do not exists")
    else:
         print("DB is exists")

def create_app():
    checkIfDBExists()
    returnFlask(__name__)

app = create_app()

This will allow you to perform any necessary steps when you discover any settings are wrong. You can also perform routing in that function. I've written such function to separate this process here:

defregister_urls(app):
    app.add_url_rule('/', 'index', index)
    return app

Post a Comment for "How To Run Function Before Flask Routing Is Starting?"