0
0
Flaskframework~20 mins

Configuration management in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Flask Config Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Flask app configuration code?
Consider this Flask app setup. What will be the value of app.config['DEBUG'] after running this code?
Flask
from flask import Flask
app = Flask(__name__)
app.config.from_mapping(DEBUG=True)
app.config['DEBUG'] = False
print(app.config['DEBUG'])
AFalse
BTrue
CNone
DRaises KeyError
Attempts:
2 left
💡 Hint
Remember that later assignments overwrite earlier ones.
📝 Syntax
intermediate
2:00remaining
Which option correctly loads configuration from a Python file in Flask?
You want to load configuration from a file named config.py. Which code snippet correctly does this?
Aapp.load_config('config.py')
Bapp.config.load_pyfile('config.py')
Capp.config.from_pyfile('config.py')
Dapp.config.from_file('config.py')
Attempts:
2 left
💡 Hint
Check Flask's official method for loading config from a Python file.
🔧 Debug
advanced
2:00remaining
What error does this Flask config code raise?
What error occurs when running this code snippet?
Flask
from flask import Flask
app = Flask(__name__)
app.config.from_pyfile('missing_config.py')
AFileNotFoundError
BKeyError
CTypeError
DNo error, loads default config
Attempts:
2 left
💡 Hint
The file does not exist in the directory.
state_output
advanced
2:00remaining
What is the value of app.config['SECRET_KEY'] after this code runs?
Given this Flask app configuration, what is the final value of app.config['SECRET_KEY']?
Flask
from flask import Flask
app = Flask(__name__)
app.config['SECRET_KEY'] = 'first'
app.config.from_mapping(SECRET_KEY='second')
app.config.update({'SECRET_KEY': 'third'})
print(app.config['SECRET_KEY'])
A'first'
BKeyError
C'second'
D'third'
Attempts:
2 left
💡 Hint
Later config updates overwrite earlier ones.
🧠 Conceptual
expert
3:00remaining
Which method is best to load environment-specific config in Flask?
You want to load different configurations for development and production environments without changing code. Which approach is best?
AHardcode config values directly in the Flask app file
BUse <code>app.config.from_object()</code> with different config classes for each environment
CManually edit <code>app.config</code> dictionary in code before running
DUse <code>app.config.from_pyfile()</code> with the same file for all environments
Attempts:
2 left
💡 Hint
Think about clean separation and easy switching of configs.