Recall & Review
beginner
What is a custom status code in Flask?
A custom status code is a user-defined HTTP response code sent from a Flask route to indicate a specific result or error beyond standard codes.
Click to reveal answer
beginner
How do you return a custom status code from a Flask route?
Return a tuple from the route with the response body and the custom status code number, e.g., return 'Error', 499.
Click to reveal answer
intermediate
Why might you use a custom status code in a Flask app?
To communicate specific application states or errors not covered by standard HTTP codes, helping clients handle responses better.
Click to reveal answer
intermediate
Can Flask recognize custom status codes automatically?
Flask allows any integer as a status code, but custom codes are not standard and may not be recognized by browsers or tools.
Click to reveal answer
beginner
Show a simple Flask route example returning a custom status code 450.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Custom status', 450Click to reveal answer
How do you specify a custom status code in a Flask route return?
✗ Incorrect
In Flask, returning a tuple with the response and status code sets the HTTP status code.
What happens if you use a non-standard status code in Flask?
✗ Incorrect
Flask sends the code, but browsers or clients may not recognize it.
Which of these is a valid way to return a custom status code 499 in Flask?
✗ Incorrect
Returning a tuple with the response and status code is the correct Flask pattern.
Why should you be careful using custom status codes?
✗ Incorrect
Custom codes may not be recognized by clients, causing confusion.
Which HTTP status code range is typically used for custom codes?
✗ Incorrect
Custom codes have no official range but often use unused numbers in 4xx or 5xx.
Explain how to return a custom status code in a Flask route and why you might do it.
Think about how Flask returns responses and why custom codes help.
You got /3 concepts.
Describe potential issues when using custom status codes in Flask applications.
Consider how browsers and APIs handle unknown codes.
You got /3 concepts.