Complete the code to import the Flask class from the flask package.
from flask import [1] app = [1](__name__)
The Flask class is imported to create the app instance.
Complete the code to define a route that returns 'Hello World!'.
@app.route('/') def home(): return [1]
The return value must be a string, so it needs quotes.
Fix the error in the code to run the Flask app only when the script is executed directly.
if __name__ == [1]: app.run(debug=True)
The special variable __name__ is compared to the string '__main__' to check if the script runs directly.
Fill both blanks to create a background task using threading to avoid blocking the main Flask app.
import threading def background_task(): print('Task running') thread = threading.Thread(target=[1]) thread.[2]()
The thread needs the function as target and start() to run in background.
Fill all three blanks to create a Flask route that starts a background task and immediately returns a response.
@app.route('/start-task') def start_task(): thread = threading.Thread(target=[1]) thread.[2]() return [3]
The route starts the background task and returns a quick message without waiting.