Complete the code to define an async route handler in Flask.
from flask import Flask app = Flask(__name__) @app.route('/') async def [1](): return 'Hello, async Flask!'
The async route handler function is named index here, which is a common name for the main page.
Complete the code to await an async function inside an async Flask route.
import asyncio from flask import Flask app = Flask(__name__) async def fetch_data(): await asyncio.sleep(1) return 'data' @app.route('/data') async def get_data(): result = await [1]() return result
awaitThe async function fetch_data is awaited inside the route handler.
Fix the error in the async Flask route by completing the decorator.
from flask import Flask app = Flask(__name__) [1]('/async') async def async_route(): return 'Async route works!'
@app.async@app.async_route which is invalidThe correct decorator for routes in Flask is @app.route, which supports async functions in modern Flask versions.
Fill both blanks to create an async Flask route that returns JSON asynchronously.
from flask import Flask, jsonify app = Flask(__name__) @app.route('/json') async def json_route(): data = await [1]() return [2](data)
json instead of jsonifyThe async function fetch_data is awaited to get data, then jsonify converts it to JSON response.
Fill all three blanks to define an async Flask route that calls two async functions and returns combined results.
from flask import Flask, jsonify app = Flask(__name__) async def fetch_user(): return {'user': 'Alice'} async def fetch_status(): return {'status': 'active'} @app.route('/combined') async def combined_route(): user = await [1]() status = await [2]() result = {**user, **[3] return jsonify(result)
The route awaits fetch_user and fetch_status, then merges the dictionaries with status to return combined JSON.