0
0
Flaskframework~10 mins

Configuration management in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load configuration from a Python file in Flask.

Flask
app = Flask(__name__)
app.config.from_pyfile([1])
Drag options to blanks, or click blank then click option'
A'config.json'
Bconfig
C'config.py'
Dconfig.py
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the filename without quotes causes an error.
Using a JSON file with from_pyfile does not work.
2fill in blank
medium

Complete the code to set a configuration value directly in Flask.

Flask
app = Flask(__name__)
app.config[[1]] = 'development'
Drag options to blanks, or click blank then click option'
A'ENV'
BENV
C'env'
Denvironment
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys causes a NameError.
Using lowercase keys does not set the expected config.
3fill in blank
hard

Fix the error in loading configuration from an object in Flask.

Flask
class Config:
    DEBUG = True

app = Flask(__name__)
app.config.from_object([1])
Drag options to blanks, or click blank then click option'
AConfig()
BConfig
C'Config'
D'config.Config'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an instance causes an error.
Passing the class name as a string without module path fails if not imported.
4fill in blank
hard

Fill both blanks to create a config dictionary with only keys starting with 'MYAPP_'.

Flask
filtered_config = {k: v for k, v in app.config.items() if k.[1]('MYAPP_') and v [2] None}
Drag options to blanks, or click blank then click option'
Astartswith
Bis not
Cendswith
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'endswith' instead of 'startswith' filters wrong keys.
Using '==' to check None causes errors.
5fill in blank
hard

Fill all three blanks to load config from environment variable and fallback to default.

Flask
import os

config_path = os.getenv([1], [2])
app.config.from_pyfile([3])
Drag options to blanks, or click blank then click option'
A'MYAPP_CONFIG'
B'default.cfg'
Cconfig_path
D'config.cfg'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the config filename directly instead of the variable.
Not providing a default fallback causes errors if env var missing.