Method: flask.helpers.make_response
Calls: 11, Exceptions: 0, Paths: 3Back
Path 1: 5 calls (0.45)
tuple (4) ('W00t', 404) (1)
Response (5)
1def make_response(*args: t.Any) -> Response:
2 """Sometimes it is necessary to set additional headers in a view. Because
3 views do not have to return response objects but can return a value that
4 is converted into a response object by Flask itself, it becomes tricky to
5 add headers to it. This function can be called instead of using a return
6 and you will get a response object which you can use to attach headers.
7
8 If view looked like this and you want to add a new header::
9
10 def index():
11 return render_template('index.html', foo=42)
12
13 You can now do something like this::
14
15 def index():
16 response = make_response(render_template('index.html', foo=42))
17 response.headers['X-Parachutes'] = 'parachutes are cool'
18 return response
19
20 This function accepts the very same arguments you can return from a
21 view function. This for example creates a response with a 404 error
22 code::
23
24 response = make_response(render_template('not_found.html'), 404)
25
26 The other use case of this function is to force the return value of a
27 view function into a response which is helpful with view
28 decorators::
29
30 response = make_response(view_function())
31 response.headers['X-Parachutes'] = 'parachutes are cool'
32
33 Internally this function does the following things:
34
35 - if no arguments are passed, it creates a new response argument
36 - if one argument is passed, :meth:`flask.Flask.make_response`
37 is invoked with it.
38 - if more than one argument is passed, the arguments are passed
39 to the :meth:`flask.Flask.make_response` function as tuple.
40
41 .. versionadded:: 0.6
42 """
43 if not args:
44 return current_app.response_class()
45 if len(args) == 1:
46 args = args[0]
47 return current_app.make_response(args) # type: ignore
Path 2: 4 calls (0.36)
('Awesome',) (2) tuple (1) ('Hello',) (1)
Response (4)
1def make_response(*args: t.Any) -> Response:
2 """Sometimes it is necessary to set additional headers in a view. Because
3 views do not have to return response objects but can return a value that
4 is converted into a response object by Flask itself, it becomes tricky to
5 add headers to it. This function can be called instead of using a return
6 and you will get a response object which you can use to attach headers.
7
8 If view looked like this and you want to add a new header::
9
10 def index():
11 return render_template('index.html', foo=42)
12
13 You can now do something like this::
14
15 def index():
16 response = make_response(render_template('index.html', foo=42))
17 response.headers['X-Parachutes'] = 'parachutes are cool'
18 return response
19
20 This function accepts the very same arguments you can return from a
21 view function. This for example creates a response with a 404 error
22 code::
23
24 response = make_response(render_template('not_found.html'), 404)
25
26 The other use case of this function is to force the return value of a
27 view function into a response which is helpful with view
28 decorators::
29
30 response = make_response(view_function())
31 response.headers['X-Parachutes'] = 'parachutes are cool'
32
33 Internally this function does the following things:
34
35 - if no arguments are passed, it creates a new response argument
36 - if one argument is passed, :meth:`flask.Flask.make_response`
37 is invoked with it.
38 - if more than one argument is passed, the arguments are passed
39 to the :meth:`flask.Flask.make_response` function as tuple.
40
41 .. versionadded:: 0.6
42 """
43 if not args:
44 return current_app.response_class()
45 if len(args) == 1:
46 args = args[0]
47 return current_app.make_response(args) # type: ignore
Path 3: 2 calls (0.18)
() (2)
Response (2)
1def make_response(*args: t.Any) -> Response:
2 """Sometimes it is necessary to set additional headers in a view. Because
3 views do not have to return response objects but can return a value that
4 is converted into a response object by Flask itself, it becomes tricky to
5 add headers to it. This function can be called instead of using a return
6 and you will get a response object which you can use to attach headers.
7
8 If view looked like this and you want to add a new header::
9
10 def index():
11 return render_template('index.html', foo=42)
12
13 You can now do something like this::
14
15 def index():
16 response = make_response(render_template('index.html', foo=42))
17 response.headers['X-Parachutes'] = 'parachutes are cool'
18 return response
19
20 This function accepts the very same arguments you can return from a
21 view function. This for example creates a response with a 404 error
22 code::
23
24 response = make_response(render_template('not_found.html'), 404)
25
26 The other use case of this function is to force the return value of a
27 view function into a response which is helpful with view
28 decorators::
29
30 response = make_response(view_function())
31 response.headers['X-Parachutes'] = 'parachutes are cool'
32
33 Internally this function does the following things:
34
35 - if no arguments are passed, it creates a new response argument
36 - if one argument is passed, :meth:`flask.Flask.make_response`
37 is invoked with it.
38 - if more than one argument is passed, the arguments are passed
39 to the :meth:`flask.Flask.make_response` function as tuple.
40
41 .. versionadded:: 0.6
42 """
43 if not args:
44 return current_app.response_class()
45 if len(args) == 1:
46 args = args[0]
47 return current_app.make_response(args) # type: ignore