Complete the code to import the Flask class from the flask package.
from flask import [1] app = [1](__name__)
The Flask class is imported from the flask package to create the app instance.
Complete the code to add the Flask-Profiler extension to the app.
from flask_profiler import Profiler app = Flask(__name__) app.config["flask_profiler"] = {"enabled": True} profiler = [1](app)
The Profiler class from flask_profiler is used to enable profiling on the Flask app.
Fix the error in the route decorator to profile the home page.
@app.route([1]) def home(): return "Hello, Flask Profiler!"
The route decorator needs a string path. The home page is at "/".
Fill both blanks to configure Flask-Profiler to store data in a SQLite database.
app.config["flask_profiler"] = { "enabled": True, "storage": [1], "storage_path": [2] }
To store profiling data in SQLite, set storage to "sqlite" and provide a file path for storage_path.
Fill all three blanks to create a custom middleware that logs request time in Flask.
import time from flask import request @app.before_request def start_timer(): [1] = time.time() setattr([2], "start_time", [1]) @app.after_request def log_request(response): duration = time.time() - getattr([3], "start_time", time.time()) print(f"Request took {duration:.4f} seconds") return response
The middleware saves the start time in the request object and calculates duration after the request.