Recall & Review
beginner
What is a Response object in Flask?
A Response object in Flask represents the HTTP response sent back to the client. It contains data like the content, status code, and headers.
Click to reveal answer
beginner
How do you create a simple Response object with custom text in Flask?
You can create it by using <code>from flask import Response</code> and then calling Response('Your text here'). For example: <code>return Response('Hello, world!')</code>Click to reveal answer
intermediate
Which parameters can you set when creating a Response object in Flask?
You can set the response body (data), status code (like 200, 404), and headers (like content-type). For example:
Response('data', status=404, headers={'Content-Type': 'text/plain'})Click to reveal answer
intermediate
What is the difference between returning a string and returning a Response object in Flask?
Returning a string lets Flask create a default Response object for you. Returning a Response object gives you full control over status codes and headers.
Click to reveal answer
beginner
How can you set a custom HTTP status code using a Response object in Flask?
Pass the status code as the
status parameter when creating the Response. Example: Response('Not found', status=404)Click to reveal answer
Which import is needed to create a Response object in Flask?
✗ Incorrect
The correct import is
from flask import Response.What is the default HTTP status code if you return a string from a Flask view?
✗ Incorrect
Flask uses status code 200 (OK) by default when returning a string.
How do you add a custom header to a Response object in Flask?
✗ Incorrect
You add headers by passing a dictionary to the
headers parameter in Response.Which of these is a valid way to create a Response with status 201?
✗ Incorrect
The correct parameter name is
status.If you want to return JSON data with a Response object, what should you set in headers?
✗ Incorrect
JSON responses should have the header
Content-Type: application/json.Explain how to create a Response object in Flask with custom text, status code, and headers.
Think about the parameters Response accepts.
You got /4 concepts.
Describe the difference between returning a string and returning a Response object in a Flask view function.
Consider control over HTTP details.
You got /4 concepts.