Home / Function/ make_response() — flask Function Reference

make_response() — flask Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  6b72679e_4d2e_b351_d7d0_f54e7825b31c["make_response()"]
  881f9803_28d6_7d77_c8d7_1098b41ccf84["helpers.py"]
  6b72679e_4d2e_b351_d7d0_f54e7825b31c -->|defined in| 881f9803_28d6_7d77_c8d7_1098b41ccf84
  884e9013_4c15_e8c6_1670_cd7bec14a56f["make_response()"]
  884e9013_4c15_e8c6_1670_cd7bec14a56f -->|calls| 6b72679e_4d2e_b351_d7d0_f54e7825b31c
  style 6b72679e_4d2e_b351_d7d0_f54e7825b31c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/helpers.py lines 138–184

def make_response(*args: t.Any) -> 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.

    If view looked like this and you want to add a new header::

        def index():
            return render_template('index.html', foo=42)

    You can now do something like this::

        def index():
            response = make_response(render_template('index.html', foo=42))
            response.headers['X-Parachutes'] = 'parachutes are cool'
            return response

    This function accepts the very same arguments you can return from a
    view function.  This for example creates a response with a 404 error
    code::

        response = make_response(render_template('not_found.html'), 404)

    The other use case of this function is to force the return value of a
    view function into a response which is helpful with view
    decorators::

        response = make_response(view_function())
        response.headers['X-Parachutes'] = 'parachutes are cool'

    Internally this function does the following things:

    -   if no arguments are passed, it creates a new response argument
    -   if one argument is passed, :meth:`flask.Flask.make_response`
        is invoked with it.
    -   if more than one argument is passed, the arguments are passed
        to the :meth:`flask.Flask.make_response` function as tuple.

    .. versionadded:: 0.6
    """
    if not args:
        return current_app.response_class()
    if len(args) == 1:
        args = args[0]
    return current_app.make_response(args)

Subdomains

Called By

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free