I'm learning web development for simple applications and I've created one that uses before_first_request
decorator. According with the new release notes, the before_first_request is deprecated and will be removed from Flask 2.3:
Deprecated since version 2.2: Will be removed in Flask 2.3. Run setup code when creating the application instead.
I don't understand how I can update my code to be complacent with Flask 2.3 and still run a function at first request without using before_first_request. Could some kind soul give me an example?
In place of the @app.before_first_request
decorated function like this previously:
@app.before_first_request
def create_tables():
db.create_all()
...
Replace that with this instead.
with app.app_context():
db.create_all()
...
Refer to documentation section on Manually Push a Context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With