Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flask-Limiter extension.
Flask
from flask_limiter import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names like RateLimiter or FlaskLimiter.
Trying to import from wrong modules.
✗ Incorrect
The Flask-Limiter extension is imported using Limiter.
2fill in blank
mediumComplete the code to create a Limiter instance with default limits.
Flask
limiter = Limiter(app, default_limits=["[1] per minute"])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using too high a limit like 100 which is less protective.
Using invalid strings without 'per minute'.
✗ Incorrect
The example uses a default limit of 5 per minute to protect the app.
3fill in blank
hardFix the error in the decorator to apply rate limiting on the route.
Flask
@limiter.[1]("3 per minute") def home(): return "Welcome!"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect decorator names like rate_limit or limiter.
Misspelling the method name.
✗ Incorrect
The correct decorator method is limit to set rate limits on routes.
4fill in blank
hardFill both blanks to create a rate limit key function using IP address.
Flask
def [2](): return request.[1] limiter = Limiter(app, key_func=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names like ip_address or client_ip.
Passing wrong function names to key_func.
✗ Incorrect
The IP address is accessed via request.remote_addr, and the key function is set to remote_addr.
5fill in blank
hardFill all three blanks to create a custom error message for rate limit exceeded.
Flask
from flask import Flask, jsonify @limiter.[1]("2 per minute") def limited_route(): return jsonify({"message": "[2]"}), [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong decorator names like rate_limit.
Using incorrect status codes like 400 or 500.
Not providing a clear error message.
✗ Incorrect
The decorator is limit, the message informs the user, and HTTP status code 429 means too many requests.