Home / Function/ make_response() — flask Function Reference

make_response() — flask Function Reference

Architecture documentation for the make_response() function in app.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  884e9013_4c15_e8c6_1670_cd7bec14a56f["make_response()"]
  9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5["Flask"]
  884e9013_4c15_e8c6_1670_cd7bec14a56f -->|defined in| 9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5
  8a660ad5_27c1_9b88_cf57_c82cb644de6c["finalize_request()"]
  8a660ad5_27c1_9b88_cf57_c82cb644de6c -->|calls| 884e9013_4c15_e8c6_1670_cd7bec14a56f
  6b72679e_4d2e_b351_d7d0_f54e7825b31c["make_response()"]
  884e9013_4c15_e8c6_1670_cd7bec14a56f -->|calls| 6b72679e_4d2e_b351_d7d0_f54e7825b31c
  style 884e9013_4c15_e8c6_1670_cd7bec14a56f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/app.py lines 1223–1363

    def make_response(self, rv: ft.ResponseReturnValue) -> Response:
        """Convert the return value from a view function to an instance of
        :attr:`response_class`.

        :param rv: the return value from the view function. The view function
            must return a response. Returning ``None``, or the view ending
            without returning, is not allowed. The following types are allowed
            for ``view_rv``:

            ``str``
                A response object is created with the string encoded to UTF-8
                as the body.

            ``bytes``
                A response object is created with the bytes as the body.

            ``dict``
                A dictionary that will be jsonify'd before being returned.

            ``list``
                A list that will be jsonify'd before being returned.

            ``generator`` or ``iterator``
                A generator that returns ``str`` or ``bytes`` to be
                streamed as the response.

            ``tuple``
                Either ``(body, status, headers)``, ``(body, status)``, or
                ``(body, headers)``, where ``body`` is any of the other types
                allowed here, ``status`` is a string or an integer, and
                ``headers`` is a dictionary or a list of ``(key, value)``
                tuples. If ``body`` is a :attr:`response_class` instance,
                ``status`` overwrites the exiting value and ``headers`` are
                extended.

            :attr:`response_class`
                The object is returned unchanged.

            other :class:`~werkzeug.wrappers.Response` class
                The object is coerced to :attr:`response_class`.

            :func:`callable`
                The function is called as a WSGI application. The result is
                used to create a response object.

        .. versionchanged:: 2.2
            A generator will be converted to a streaming response.
            A list will be converted to a JSON response.

        .. versionchanged:: 1.1
            A dict will be converted to a JSON response.

        .. versionchanged:: 0.9
           Previously a tuple was interpreted as the arguments for the
           response object.
        """

        status: int | None = None
        headers: HeadersValue | None = None

        # unpack tuple returns
        if isinstance(rv, tuple):
            len_rv = len(rv)

            # a 3-tuple is unpacked directly
            if len_rv == 3:
                rv, status, headers = rv  # type: ignore[misc]
            # decide if a 2-tuple has status or headers
            elif len_rv == 2:
                if isinstance(rv[1], (Headers, dict, tuple, list)):
                    rv, headers = rv  # pyright: ignore
                else:
                    rv, status = rv  # type: ignore[assignment,misc]
            # other sized tuples are not allowed
            else:
                raise TypeError(
                    "The view function did not return a valid response tuple."
                    " The tuple must have the form (body, status, headers),"
                    " (body, status), or (body, headers)."
                )

Subdomains

Defined In

Called By

Frequently Asked Questions

What does make_response() do?
make_response() is a function in the flask codebase, defined in src/flask/app.py.
Where is make_response() defined?
make_response() is defined in src/flask/app.py at line 1223.
What does make_response() call?
make_response() calls 1 function(s): make_response.
What calls make_response()?
make_response() is called by 1 function(s): finalize_request.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free