Challenge - 5 Problems
Flask Config Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2: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'])
Attempts:
2 left
💡 Hint
Remember that later assignments overwrite earlier ones.
✗ Incorrect
The app config is first set with DEBUG=True, but then immediately set to False. So the final value is False.
📝 Syntax
intermediate2: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?Attempts:
2 left
💡 Hint
Check Flask's official method for loading config from a Python file.
✗ Incorrect
The correct method is from_pyfile. Other options are invalid method names.
🔧 Debug
advanced2: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')
Attempts:
2 left
💡 Hint
The file does not exist in the directory.
✗ Incorrect
Trying to load a missing config file raises a FileNotFoundError.
❓ state_output
advanced2: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'])
Attempts:
2 left
💡 Hint
Later config updates overwrite earlier ones.
✗ Incorrect
The last update sets SECRET_KEY to 'third', so that is the final value.
🧠 Conceptual
expert3: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?
Attempts:
2 left
💡 Hint
Think about clean separation and easy switching of configs.
✗ Incorrect
Using from_object() with different classes allows clean, maintainable environment-specific configs.