django-haystack+jieba全文索引(前后端分离版)
-
django-haystack前后端分离版,和不分离版差不多,区别就是需要重写SearchView
-
前先看完不分离版:https://blog.csdn.net/weixin_43841577/article/details/89532313
-
重写SearchView
-
view.py
from haystack.views import SearchViewclass MySearchView(SearchView): #template = 'searchs.html' #我们通过重写extra_context 来定义我们自己的变量, #通过看源码,extra_context 默认返回的是空,然后再get_context方法里面,把extra_context #返回的内容加到我们self.context字典里 def create_response(self): context = super().get_context() keyword = self.request.GET.get('q', None) # 关键子为q if not keyword: return JsonResponse({'message':'没有相关信息'}) else: print(keyword) pr