When I am trying to send values in JsonResponse then The error is coming(object of type QuerySet is not JSON serializable )
def ajaxAgent(request):
data = CommCenter.objects.values()
responseData = { 'status': 'success', 'msg' : data}
return JsonResponse(responseData)
Please find here the answer:
from django.http import JsonResponse
def some_view(request):
data = list(SomeModel.objects.values())
return JsonResponse(data, safe=False) # or JsonResponse({'data': data})
What worked for me was using values_list() and converting to list using list
def ajaxAgent(request):
data = CommCenter.objects.filter().values_list()
responseData = { 'status': 'success', 'msg' : list(data)}
return JsonResponse(responseData)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With