你可以使用
JsonResponse
发送JSON数据。(您可以在文档中看到详细信息
here
)
像下面
from django.http import JsonResponse
class DetailView(TemplateView):
template_name = 'list.html'
def get(self,request):
list_view = GetList().get_data(self.request)
movie_list = list.json()
return JsonResponse(movie_list, status=200)
顺便说一句,您必须知道您的数据类型。
JSON响应
自动序列化数据,这样就不必使用
json()
为您的数据。