码迷,mamicode.com
首页 > 其他好文 > 详细

haystack 前后端分离,重写方法

时间:2019-04-26 22:36:57      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:for   rate   dict   rom   djang   ack   return   self   views   

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()),

haystack 前后端分离,重写方法

标签:for   rate   dict   rom   djang   ack   return   self   views   

原文地址:https://www.cnblogs.com/wrqysrt/p/10776789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!