0
0
Flaskframework~10 mins

Environment-based configuration 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 the configuration from an environment variable.

Flask
app.config.from_envvar('[1]')
Drag options to blanks, or click blank then click option'
ACONFIG_PATH
Bconfig.py
CENV_CONFIG
DAPP_SETTINGS
Attempts:
3 left
💡 Hint
Common Mistakes
Using a file name instead of an environment variable name.
Confusing environment variable names with config file names.
2fill in blank
medium

Complete the code to set the Flask app configuration from a Python object based on the environment variable.

Flask
app.config.from_object('[1]')
Drag options to blanks, or click blank then click option'
Aos.environ.get('FLASK_ENV')
Bconfig.ProductionConfig
Cconfig.DevelopmentConfig
Dconfig.TestingConfig
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the environment variable value directly instead of a config class path.
Using the environment variable getter instead of a config class.
3fill in blank
hard

Fix the error in the code to correctly load configuration from environment variables using Flask's config.from_mapping.

Flask
app.config.from_mapping({ 'DEBUG': [1] })
Drag options to blanks, or click blank then click option'
Aos.environ.get('DEBUG') == 'True'
Bos.environ['DEBUG']
Cos.getenv('DEBUG')
Dos.getenv('DEBUG', False)
Attempts:
3 left
💡 Hint
Common Mistakes
Using os.getenv without converting to boolean.
Using os.environ which raises error if variable missing.
4fill in blank
hard

Fill both blanks to create a config dictionary that sets SECRET_KEY and DATABASE_URL from environment variables.

Flask
config = { 'SECRET_KEY': [1], 'DATABASE_URL': [2] }
Drag options to blanks, or click blank then click option'
Aos.environ.get('SECRET_KEY')
Bos.getenv('DATABASE_URL')
Cos.environ['DATABASE_URL']
Dos.getenv('SECRET_KEY')
Attempts:
3 left
💡 Hint
Common Mistakes
Using os.environ which raises KeyError if variable missing.
Mixing up environment variable names.
5fill in blank
hard

Fill all three blanks to load configuration from a file path stored in an environment variable, then override with a dictionary from environment variables.

Flask
app.config.from_pyfile([1])
app.config.update({ 'DEBUG': [2], 'TESTING': [3] })
Drag options to blanks, or click blank then click option'
Aos.environ['CONFIG_FILE']
Bos.getenv('DEBUG') == 'True'
Cos.getenv('TESTING') == 'True'
Dos.environ.get('CONFIG_FILE')
Attempts:
3 left
💡 Hint
Common Mistakes
Using os.getenv for config file path which may be None.
Not converting string flags to booleans.