Complete the code to create a Flask route that returns 'Hello World!'.
from flask import Flask app = Flask(__name__) @app.route([1]) def hello(): return 'Hello World!'
The route decorator needs the URL path starting with a slash, so "/hello" is correct.
Complete the code to import the Flask class correctly.
[1] Flask
app = Flask(__name__)The correct way to import the Flask class is from flask import Flask.
Fix the error in the route decorator to make it a valid Flask route.
@app.route([1]) def greet(): return 'Hi there!'
The route path must start with a slash and be a string, so '/greet' or "/greet" is correct.
Fill both blanks to create a Flask route that returns JSON data with a message.
from flask import Flask, [1] app = Flask(__name__) @app.route([2]) def api(): return [3]({"message": "Hello API"})
We import jsonify to return JSON data, use the route path "/api", and call jsonify to send the JSON response.
Fill all three blanks to create a Flask route that accepts a variable part in the URL and returns a greeting.
from flask import Flask app = Flask(__name__) @app.route([1]) def greet_user(name): return f"Hello, [2]!" if __name__ == '__main__': app.run([3])
The route uses a variable URL part <name>, the function uses the variable name, and app.run(debug=True) starts the server with debug mode.