Check if execution is within a request context. This allows a controlled way to act if there is a request context available, or silently not act if not. For example, .. code-block:: python if has_request_context(): log.info("Request endpoint %s", request.endpoint)
()
| 452 | |
| 453 | |
| 454 | def has_request_context() -> bool: |
| 455 | """Check if execution is within a request context. |
| 456 | |
| 457 | This allows a controlled way to act if there is a request context |
| 458 | available, or silently not act if not. For example, |
| 459 | |
| 460 | .. code-block:: python |
| 461 | |
| 462 | if has_request_context(): |
| 463 | log.info("Request endpoint %s", request.endpoint) |
| 464 | |
| 465 | See also :func:`has_app_context`. |
| 466 | """ |
| 467 | return _cv_request.get(None) is not None |
| 468 | |
| 469 | |
| 470 | def has_websocket_context() -> bool: |
searching dependent graphs…