I need to send the list "search" by response, the problem is that I can not serialize it with the library "JSON" that brings django by default and send it by the URL to the Frontend, how can I serialize the list and send it as any object json to the frontend with response? This is the view:
class FindValue(APIView):
def post(self, request):
value_json = json.loads(request.body.decode("utf-8"))
productos_similares = Product.objects.filter(name_product__icontains=value_json[0]["value"])
categorias_similares = Category.objects.filter(name_category__icontains=value_json[0]["value"])
busqueda = []
for prod in productos_similares:
busqueda.append(prod)
for cat in categorias_similares:
busqueda.append(cat)
return Response(busqueda, status=200)
The error in the console is summarized in:
return super(JSONEncoder, self).default(obj) File "C:\Python27\lib\json\encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: is not serializable JSON