Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to run a Flask app in development mode.
Flask
if __name__ == '__main__': app.run(debug=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting debug to False disables helpful error messages.
Using None or 0 does not enable debug mode.
✗ Incorrect
Setting debug=True runs the Flask app in development mode with helpful error messages and auto-reload.
2fill in blank
mediumComplete the code to import the production-ready WSGI server.
Flask
from [1] import WSGIServer
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from flask or werkzeug.serving is for development only.
http.server is not suitable for production Flask apps.
✗ Incorrect
gevent.pywsgi provides a production-ready WSGI server for Flask apps.
3fill in blank
hardFix the error in the production server start command.
Flask
http_server = WSGIServer(('0.0.0.0', [1]), app) http_server.serve_forever()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the port number causes a type error.
Passing the app object as the port causes errors.
✗ Incorrect
The port number must be an integer, not a string, so use 5000 without quotes.
4fill in blank
hardFill both blanks to create a dictionary comprehension filtering environment variables.
Flask
prod_env = {key: value for key, value in [1].items() if key.[2]('PROD_')} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using os.getenv returns a single value, not a dictionary.
Using 'in' instead of 'startswith' does not filter keys correctly.
✗ Incorrect
Use os.environ to access environment variables and startswith to filter keys starting with 'PROD_'.
5fill in blank
hardFill all three blanks to configure Flask app for production.
Flask
app.config['DEBUG'] = [1] app.config['TESTING'] = [2] app.config['ENV'] = '[3]'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving debug or testing enabled in production risks security.
Setting ENV to 'development' causes unwanted debug features.
✗ Incorrect
In production, DEBUG and TESTING should be False, and ENV set to 'production'.