Whooshの検索結果からJSONのシリアライズ可能なデータをクライアントに返すことができますか?Whooshの検索結果がJsonのシリアル化可能ではありません
ヒューという音検索出力(Pythonのオブジェクトのリスト):これをやって
[<Hit {'content': 'This is the second example.', 'path': '/b', 'icon': '/icons/sheep.png', 'title': 'Second try'}>, <Hit {'content': 'Examples are many second.', 'path': '/c', 'icon': '/icons/book.png', 'title': "Third time's the charm"}>]
エラー:私は別のクラス
class DataSerializer(serializers.Serializer):
icon=serializers.CharField()
content=serializers.CharField()
path=serializers.CharField()
title=serializers.CharField()
が、エラーを作るしようとしている
return JsonReponse({"data": whoosh_results})
TypeError: <Hit {'content': 'This is the second example.', 'path': '/b', 'icon': '/icons/sheep.png', 'title': 'Second try'}> is not JSON serializable
ヒットオブジェクトに属性 'アイコン'がないことになります
検索に使用したコードを表示できますか? – zaidfazil
'dict'でラップしようとしましたか? 'return JsonReponse({" data ":dict(whoosh_results)})のように' – Igonato