商品详情页 ,浏览历史中不显示图片和详细信息,,,抛出异常ERROR basehttp 124 "POST /admin/goods/sku/2/change/ HTTP/1.1" 500 19357


问题:
商品详情页
浏览历史中不显示图片和详细信息


抛出异常
django.template.exceptions.TemplateDoesNotExist: search/indexes/goods/sku_text.txt
ERROR basehttp 124 "POST /admin/goods/sku/2/change/ HTTP/1.1" 500 193573



TemplateDoesNotExist at /admin/goods/sku/1/change/
search/indexes/goods/sku_text.txt


使用admin.ModelAdmin时obj.save()保存失败



解决方法:


在SKUIndex建立的字段,都可以借助haystack由elasticsearch搜索引擎查询。


其中text字段我们声明为document=True,表名该字段是主要进行关键字查询的字段, 该字段的索引值可以由多个数据库模型类字段组成,具体由哪些模型类字段组成,我们用use_template=True表示后续通过模板来指明。其他字段都是通过model_attr选项指明引用数据库模型类的特定字段。


在REST framework中,索引类的字段会作为查询结果返回数据的来源。


在templates目录中创建text字段使用的模板文件


具体在templates/search/indexes/goods/sku_text.txt文件中定义


{{ object.name }}
{{ object.caption }}
{{ object.id }}
此模板指明当将关键词通过text参数名传递时,可以通过sku的name、caption、id来进行关键字索引查询

猜你喜欢

转载自blog.csdn.net/caomei_huacha/article/details/80876866