def viewfunc(request):
    do_something()
try:
    with transaction.atomic():
        thing_that_might_fail()
except SomeError:
    handle_exception()
render_response()
Django - Rollback save with transaction atomic