Home > Blockchain >  How to return jsonResponse for single object model filtered on Django?
How to return jsonResponse for single object model filtered on Django?

Time:01-12

I have single object filtered as below.

backTest= BackTest.objects.first()

I would like to return this object as jsonResponse.

data = dumps(backTest)
return JsonResponse(data)

I got error message as below.

Object of type BackTest is not JSON serializable

Any advice or guidance on this would be greatly appreciated, Thanks.

CodePudding user response:

For Django 1.7 ,use this :

from django.http import JsonResponse
backTest= BackTest.objects.first()
return JsonResponse({'backtest':backTest})
  •  Tags:  
  • Related