我们的代码有定制的中间件来记录请求和响应,所以我们可以记录API活动。你知道吗
def process_response(self, request, response):
user = None
try:
if request.user.is_authenticated():
user = request.user
the_record = Record(
requestUser=user,
requestPath=request.path,
requestMethod=request.method)
the_record.save()
except:
pass
在响应方法的过程中,我们创建对象并保存它。如果API方法标记为@transaction.atomic
,则会出现日志消息autocommit cannot be used inside a transaction
。你知道吗
方法中没有异常,但只在数据库中记录,在这种情况下,该特定API调用不存在。你知道吗
有什么解释为什么会出现自动提交日志消息吗?也许使用模型管理器create
而不是save
方法?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐