2

How does "app = Flask(name)" works exactly in a flask application? I a learning Flask and trying to understand every line of the code and its' purpose. Could anyone please clarify the significance of the above statement.

1 Answers1

2

Slightly modified from the tutorial's explanation here: https://flask.palletsprojects.com/en/1.1.x/tutorial/factory/

app = Flask(__name__) # creates the Flask instance.

__name__ is the name of the current Python module. The app needs to know where it’s located to set up some paths, and __name__ is a convenient way to tell it that.

In other words: Flask is a class, as seen here: https://github.com/pallets/flask/blob/master/src/flask/app.py#L87, and you're creating one instance of that class.

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223