Complete the code to create a Flask blueprint named 'v1'.
from flask import Blueprint api_v1 = Blueprint('v1', __name__, url_prefix='/api/v1') @api_v1.route('/hello') def hello(): return 'Hello from version 1!' app.register_blueprint([1])
You register the blueprint object api_v1 with the Flask app to enable the routes under '/api/v1'.
Complete the code to create a second blueprint for API version 2 with prefix '/api/v2'.
api_v2 = Blueprint('v2', __name__, url_prefix=[1]) @api_v2.route('/hello') def hello_v2(): return 'Hello from version 2!' app.register_blueprint(api_v2)
The URL prefix for version 2 API is '/api/v2' to keep versioning consistent.
Fix the error in the route decorator to correctly define a GET endpoint in the blueprint.
@api_v1.route('/status', methods=[1]) def status(): return {'status': 'ok'}
The methods argument expects a list of HTTP methods as strings, so ['GET'] is correct.
Fill both blanks to register blueprints for v1 and v2 with the Flask app.
app = Flask(__name__) app.[1]_blueprint(api_v1) app.[2]_blueprint(api_v2)
The correct method to add a blueprint to the app is register_blueprint.
Fill all three blanks to create a versioned API blueprint with a route that returns JSON.
from flask import Blueprint, jsonify api_[1] = Blueprint('v[2]', __name__, url_prefix=[3]) @api_[1].route('/info') def info(): return jsonify({'version': 'v[2]', 'status': 'running'})
The blueprint variable and name use '1' for version 1, and the URL prefix is '/api/v1'.