Complete the code to define a route in Flask that shows 'Hello World!'.
from flask import Flask app = Flask(__name__) @app.route([1]) def hello(): return 'Hello World!'
The @app.route decorator defines the URL path. It must start with a slash, so "/hello" is correct.
Complete the code to run the Flask app only if the script is executed directly.
if __name__ == [1]: app.run(debug=True)
The special variable __name__ equals "__main__" when the script is run directly, so this condition ensures the app runs only then.
Fix the error in the route decorator to correctly map the URL '/about'.
@app.route([1]) def about(): return 'About page'
The route path must start with a slash / to be valid, so "/about" is correct.
Fill both blanks to create a route that accepts a username parameter and returns a greeting.
@app.route([1]) def greet_user([2]): return f"Hello, {username}!"
The route must include the parameter in angle brackets, and the function must accept the same parameter name.
Fill all three blanks to create a route that returns a JSON response with a message and status code.
from flask import jsonify @app.route([1]) def status(): response = [2]({{"message": "OK"}}) response.status_code = [3] return response
The route path is "/status", jsonify creates a JSON response, and 200 is the HTTP status code for OK.