3

Simply that, I want to send some data after making a delete for a DeleteView without the necessity of load a success_url, I used to do that within the form_valid method in CreateViewand UpdateView but I don't know which method call after making the delete for return a HttpResponse with some JSON data.

Any ideas?

4

1 回答 1

18

你可能想delete()用类似的东西覆盖:

from django.http import JsonResponse
from django.views.generic import DeleteView


class MyDeleteView(DeleteView)
    def delete(self, request, *args, **kwargs):
        self.get_object().delete()
        payload = {'delete': 'ok'}
        return JsonResponse(payload)

我想你需要复制你覆盖的代码有点遗憾。

如果您不确定,请查看 CCBV... http://ccbv.co.uk/DeleteView/

免责声明:我制作了 CCBV。

于 2013-07-24T17:24:46.707 回答