Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 检查烧瓶请求上下文是否可用_Python_Logging_Flask_Werkzeug - Fatal编程技术网

Python 检查烧瓶请求上下文是否可用

Python 检查烧瓶请求上下文是否可用,python,logging,flask,werkzeug,Python,Logging,Flask,Werkzeug,在烧瓶请求期间进行日志记录时,我想从上下文变量(request,session)中记录一些数据,但如果不是,则使用默认行为 我正在使用尝试。。。除了日志记录.格式化程序中的块。有没有更好的方法来检查请求上下文 try: record.user = session['user_name'] record.very_important_data = request.super_secret except Exception: record.user = None 使用或 或

在烧瓶请求期间进行日志记录时,我想从上下文变量(
request
session
)中记录一些数据,但如果不是,则使用默认行为

我正在使用
尝试。。。除了
日志记录.格式化程序中的
。有没有更好的方法来检查请求上下文

try:
    record.user = session['user_name']
    record.very_important_data = request.super_secret
except Exception:
    record.user = None
使用或

或者,
当前应用程序
g
请求
,以及
会话
都是
本地代理
的实例。如果代理未绑定,则当作为布尔值处理时,它将为
False

if request:
    # request is active
if request:
    # request is active