Flask Flashcards

1
Q

What’s ‘create_app’?

A

create_app is the application factory function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the point of __name__ in the following:

app = Flask(__name__, instance_relative_config=True)

A

_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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s the point of instance_relative_config=True in the following:

app = Flask(__name__, instance_relative_config=True)

A

instance_relative_config=True tells the app that configuration files are relative to the instance folder. The instance folder is located outside the flaskr package and can hold local data that shouldn’t be committed to version control, such as configuration secrets and the database file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the app.config.from_mapping() do?

A

sets some default configuration that the app will use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s the arguments for app.config.from_mapping()?

A

SECRET_KEY is used by Flask and extensions to keep data safe. It’s set to ‘dev’ to provide a convenient value during development, but it should be overridden with a random value when deploying.

DATABASE is the path where the SQLite database file will be saved. It’s under app.instance_path, which is the path that Flask has chosen for the instance folder. You’ll learn more about the database in the next section.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what’s app.config.from_pyfile()?

A

overrides the default configuration with values taken from the config.py file in the instance folder if it exists. For example, when deploying, this can be used to set a real SECRET_KEY.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what does the test_config argument do for app.config.from_pyfile()?

A

test_config can also be passed to the factory, and will be used instead of the instance configuration. This is so the tests you’ll write later in the tutorial can be configured independently of any development values you have configured.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what the purpose of os.makedirs() within a flask app?

A

ensures that app.instance_path exists. Flask doesn’t create the instance folder automatically, but it needs to be created because your project will create the SQLite database file there.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly