Question 27
Consider the following Flask application.
from flask import Flask, abort, requestapp = Flask(__name__)
courses = { "IT2001": "Web Development", "IT2002": "Database Systems", "IT2003": "Software Engineering", "IT2004": "Data Structures"}
@app.route('/course')def get_course(): course_id = request.args.get('id') level = request.args.get('level', 'beginner')
if not course_id: abort(400, "Bad Request: Course ID is required")
if course_id not in courses: abort(404, "Not Found: Course does not exist") return f'<h2>{courses[course_id]} - Level: {level.title()}</h2>'
@app.route('/search')def search_courses(): query = request.args.get('q') min_length = int(request.args.get('min', 3)) if not query or len(query) < min_length: abort(422, "Unprocessable Entity: Query too short")
results = [name for name in courses.values() if query.lower() in name.lower()] if not results:
return '<p>No courses found</p>'
return f'<ul>{"".join([f"<li>{course}</li>" for course in results])}</ul>'
app.run(debug=True)Based on the above data, answer the given subquestions.
Analyze the following URLs and their expected behaviors. Which statement is CORRECT?