Complete the code to import the Flask class correctly.
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 access the current request object inside a view function.
from flask import Flask, [1] app = Flask(__name__) @app.route('/') def home(): user_agent = [1].headers.get('User-Agent') return f"Your agent is {user_agent}"
The request object gives access to details about the current HTTP request.
Fix the error in accessing the Flask application context variable.
from flask import Flask, current_app app = Flask(__name__) with app.[1](): print('App name:', current_app.name)
The app_context() method creates the application context needed to access app variables safely.
Fill both blanks to create a dictionary comprehension that stores request header lengths only if the header exists.
from flask import request header_lengths = {header: len(request.headers.get(header)) for header in ['User-Agent', 'Host'] if request.headers.get([1]) [2] None}
We check if the header exists by comparing it to None with '!=' before getting its length.
Fill all three blanks to create a dictionary comprehension that stores uppercase header names and their values if the value length is greater than 5.
from flask import request filtered_headers = [1]: [2] for [3], [2] in request.headers.items() if len([2]) > 5
The comprehension uses header.upper() as keys, header as the variable for keys, and value as the variable for values.