Check if Flask request context is available

Use has_request_context or has_app_context.

if has_request_context():
    # request is active

Alternatively, current_app, g, request, and session are all instances of LocalProxy. If a proxy is not bound, it will be False when treated as a boolean.

if request:
    # request is active

Leave a Comment