Complete the code to create a Flask app instance.
from flask import Flask app = Flask([1])
The Flask app instance requires the current module name, which is given by __name__.
Complete the code to define a route that returns 'Hello World!'.
@app.route([1]) def hello(): return 'Hello World!'
The root URL '/' is the common pattern for the home page route.
Fix the error in the code to run the Flask app only when the script is executed directly.
if [1] == '__main__': app.run(debug=True)
The special variable __name__ equals '__main__' when the script runs directly.
Fill both blanks to create a route that accepts a username parameter and returns a greeting.
@app.route('/user/<[1]>') def greet([2]): return f'Hello, {{ [2] }}!'
The route parameter and function argument must match to pass the username correctly.
Fill all three blanks to create a dictionary comprehension that maps route names to their functions if the function name starts with 'view_'.
routes = { [1]: [2] for [3] in dir(app) if [1].startswith('view_') }The comprehension iterates over function names, uses getattr to get the function, and filters by name prefix.