5

Example: db.init_app(app)

What is purpose of init_app function in Flask? Is this like any other method?

variable
  • 8,262
  • 9
  • 95
  • 215

3 Answers3

7

A number of packages provide an init_app() method. It's a way of constructing an instance of the particular package, then letting it know about the Flask instance (e.g., so that configuration details can be copied). Mechanically, it's just like any other instance method.

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46
0

This is a way to safely bind database handler to Flask app in a way that manages connections.

https://flask-sqlalchemy.palletsprojects.com/en/2.x/api/#flask_sqlalchemy.SQLAlchemy.init_app

Šimon Kocúrek
  • 1,591
  • 1
  • 12
  • 22
0

It is used to control the integration of a package to one or more Flask applications. Depending on how you initialize the object it is usable right away or will attach as needed to a Flask application. In the case of db.init_app(app) the app is your flask application,the object must have been created initially.

Tinu
  • 11
  • 2