Complete the code to abort with a 404 error in Flask.
from flask import Flask, [1] app = Flask(__name__) @app.route('/item/<int:id>') def get_item(id): if id != 1: [1](404) return 'Item found'
The abort function is used to stop the request and return an HTTP error code like 404.
Complete the code to abort with a 403 Forbidden error when access is denied.
from flask import Flask, abort app = Flask(__name__) @app.route('/admin') def admin_panel(): user_role = 'guest' if user_role != 'admin': [1](403) return 'Welcome admin!'
Use abort(403) to stop the request and send a 403 Forbidden error.
Fix the error in the code to abort with a 400 Bad Request error correctly.
from flask import Flask, abort app = Flask(__name__) @app.route('/submit') def submit(): data = None if data is None: [1](400) return 'Data received'
You must call abort with the status code as an argument like abort(400). But since the code already has (400) in the code, the blank is only for the function name abort.
Fill both blanks to abort with a 500 Internal Server Error and import the correct function.
from flask import Flask, [1] app = Flask(__name__) @app.route('/error') def error(): [2](500) return 'This will not run'
You import abort and call abort(500) to stop the request with a 500 error.
Fill all three blanks to abort with a 401 Unauthorized error, import the function, and use it correctly.
from flask import Flask, [1] app = Flask(__name__) @app.route('/login') def login(): authorized = False if not authorized: [2]([3]) return 'Welcome!'
Import abort, call abort(401) to stop the request with a 401 Unauthorized error.