make_response
Sometimes it is necessary to set additional headers in a view. Because views do not have to return response objects but can return a value that is converted into a response object by Flask itself, it becomes tricky to add headers to it. This function can be called instead of using a return and you will get a response object which you can use to attach headers.
def make_response(
args: t.Any
) - > Response
Creates a response object from the given arguments, allowing additional headers to be set. This function accepts the same arguments that a view function can return, or it can create an empty response if no arguments are provided.
Parameters
| Name | Type | Description |
|---|---|---|
| args | t.Any | The arguments to convert into a response. This can be a single value (like a rendered template or a string), multiple values (like a rendered template and a status code), or no arguments to create an empty response. These arguments are passed to Flask's internal make_response function. |
Returns
| Type | Description |
|---|---|
Response | A Flask Response object that can be modified (e.g., to add headers) and then returned from a view function. |