MCPcopy
hub / github.com/pallets/flask / teardown_request

Method teardown_request

src/flask/sansio/scaffold.py:508–539  ·  view source on GitHub ↗

Register a function to be called when the request context is popped. Typically this happens at the end of each request, but contexts may be pushed manually as well during testing. .. code-block:: python with app.test_request_context(): ...

(self, f: T_teardown)

Source from the content-addressed store, hash-verified

506
507 @setupmethod
508 def teardown_request(self, f: T_teardown) -> T_teardown:
509 """Register a function to be called when the request context is
510 popped. Typically this happens at the end of each request, but
511 contexts may be pushed manually as well during testing.
512
513 .. code-block:: python
514
515 with app.test_request_context():
516 ...
517
518 When the ``with`` block exits (or ``ctx.pop()`` is called), the
519 teardown functions are called just before the request context is
520 made inactive.
521
522 When a teardown function was called because of an unhandled
523 exception it will be passed an error object. If an
524 :meth:`errorhandler` is registered, it will handle the exception
525 and the teardown will not receive it.
526
527 Teardown functions must avoid raising exceptions. If they
528 execute code that might fail they must surround that code with a
529 ``try``/``except`` block and log any errors.
530
531 The return values of teardown functions are ignored.
532
533 This is available on both app and blueprint objects. When used on an app, this
534 executes after every request. When used on a blueprint, this executes after
535 every request that the blueprint handles. To register with a blueprint and
536 execute after every request, use :meth:`.Blueprint.teardown_app_request`.
537 """
538 self.teardown_request_funcs.setdefault(None, []).append(f)
539 return f
540
541 @setupmethod
542 def context_processor(

Callers

nothing calls this directly

Calls 1

setdefaultMethod · 0.80

Tested by

no test coverage detected