事物都执行或都不执行

from django.db import transaction

try:
  with transaction.atomic():
  ......
  return Response({"code": 200,"msg":"成功"})

except IntegrityError:
  return Response({"code": 502})

原文地址:https://www.cnblogs.com/aa1bb2/p/14097614.html