I have defined the following code in the views.py I am getting TypeError : Object of type function is not JSON serializable
Libaries:
from django.db.models.query import QuerySet
from django.shortcuts import render
from django.http import HttpResponse , Http404 , JsonResponse
import json
from json import JSONEncoder
from FeedPost.models import trill
def home(request, *args, **kwargs):
return render(request, "feed.html", context={}, status=200)
Where the error occured
def trills_list_view(request, *args , **kwargs):
qs = trill.objects.all()
trills_list = [{"id": x.id, "name": x.name} for x in qs]
data = {
"response": trill_list
}
return JsonResponse(data)
def trill_list(request, trill_id, *args, **kwargs):
data = {
"id" : trill_id,
}
status = 200
try:
obj = trill.objects.get(id=trill_id)
data['name'] =obj.name
except:
data['message'] = "Not found"
status = 404
return JsonResponse(data, status=status)