haystack 前后端分离,重写方法

from haystack.views import SearchView
from django.http import JsonResponse

class MysearchView(SearchView):
def create_response(self):
"""
Generates the actual HttpResponse to send back to the user.
"""

context = self.get_context()
data_list=[]
data_dict={}
for i in context['page'].object_list:
data_dict['id']=i.object.id
data_dict['name']=i.object.name
data_dict['content'] = i.object.content
data_list.append(data_dict)
# print(context['page'].object_list)
#
return JsonResponse(data_list,safe=False,json_dumps_params={'ensure_ascii':False})



url
url(r'^search/', search.MysearchView()),
原文地址:https://www.cnblogs.com/wrqysrt/p/10776789.html