Complete the code to define a route that accepts an integer parameter named <user_id>.
from flask import Flask app = Flask(__name__) @app.route('/user/[1]') def show_user(user_id): return f"User ID is {user_id}"
Using
Complete the code to define a route that accepts a floating-point number parameter named <price>.
from flask import Flask app = Flask(__name__) @app.route('/price/[1]') def show_price(price): return f"Price is {price}"
The <float:price> converter converts the URL part to a floating-point number.
Fix the error in the route to accept a file path parameter named <filepath> that can include slashes.
from flask import Flask app = Flask(__name__) @app.route('/files/[1]') def show_file(filepath): return f"File path is {filepath}"
The <path:filepath> converter allows slashes in the parameter, capturing the full path.
Fill both blanks to create a route that accepts an integer <post_id> and a path <filename>.
from flask import Flask app = Flask(__name__) @app.route('/post/[1]/file/[2]') def show_post_file(post_id, filename): return f"Post {post_id}, File {filename}"
The first blank uses <int:post_id> to get an integer post ID. The second uses <path:filename> to accept a file path with slashes.
Fill all three blanks to create a route that accepts a float <rating>, an int <item_id>, and a path <image_path>.
from flask import Flask app = Flask(__name__) @app.route('/rate/[1]/item/[2]/image/[3]') def show_rating(rating, item_id, image_path): return f"Rating: {rating}, Item: {item_id}, Image: {image_path}"
The route uses <float:rating> for decimal ratings, <int:item_id> for integer item IDs, and <path:image_path> to accept image paths with slashes.