Complete the code to import the Flask class from the flask module.
from flask import [1] app = Flask(__name__)
The Flask class is imported from the flask module to create the app instance.
Complete the code to define a route for the home page that returns 'Hello World!'.
@app.route('/') def home(): return [1]
The route function returns the string 'Hello World!' to display on the home page.
Fix the error in the code to get JSON data from a POST request.
from flask import request @app.route('/data', methods=['POST']) def data(): json_data = request.[1] return json_data
The request object has a 'json' attribute that holds the parsed JSON data from the request body.
Fill both blanks to create a route that updates a user by ID using PUT method.
@app.route('/user/<int:id>', methods=[[1]]) def update_user(id): data = request.[2] # update logic here return 'User updated'
The route must accept PUT requests, and the data is accessed from request.json for JSON payload.
Fill all three blanks to create a route that deletes a user by ID and returns JSON confirmation.
@app.route('/user/<int:id>', methods=[[1]]) def delete_user(id): # delete logic here return [2]({'message': 'User deleted', 'id': [3])
The route uses DELETE method, returns JSON using jsonify, and includes the user id in the response.