[Answered ]-Object of type 'xxx' is not JSON serializable Django UpdateView

1👍

In the post method of your UpdateView, you’re trying to return a JsonResponse

return JsonResponse(data, safe=False)

But if you look at your code, data is a Form object when the action is ‘edit’.

if action == 'edit':
    # form = CategoryForm(request.POST)
    form = self.get_form()
    data = form.save()

You need to serialize that form before trying to send it as a JSonResponse just like you did for the other actions. The variable "data" has to be a dictionary.

https://docs.djangoproject.com/en/3.2/ref/request-response/#jsonresponse-objects

Leave a comment