第一种
from django.db import transaction
with transaction.atomic():
...
第二种
@transaction.atomic
def post(self,request):
...
sid=transaction.savepoint() #开启事务
...
transaction.savepoint_rollback(sid) # 回滚
...
transaction.savepoint_commit(sid) # 提交
原文:https://www.cnblogs.com/huanghongzheng/p/11671361.html