Today, I was watching the official tutorial of flask. In the first part, I encountered a problem in creating an application. He created a function of create_app in _ _ init__.py, and then wrote some configuration information. I didn"t see him call it. How did it run? I know that the file _ _ init__.py will run automatically, but will the functions created in it also run automatically? The official code is as follows
mkdir flaskr
flaskr/__init__.py
import os
from flask import Flask
def create_app(test_config=None):
-sharp create and configure the app
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY="dev",
DATABASE=os.path.join(app.instance_path, "flaskr.sqlite"),
)
if test_config is None:
-sharp load the instance config, if it exists, when not testing
app.config.from_pyfile("config.py", silent=True)
else:
-sharp load the test config if passed in
app.config.from_mapping(test_config)
-sharp ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
-sharp a simple page that says hello
@app.route("/hello")
def hello():
return "Hello, World!"
return app
export FLASK_APP=flaskr
export FLASK_ENV=development
flask run
so it runs, but how does it run? how is create_app called?
Thank you!