相关疑难解决方法(0)

<Django object>不是JSON可序列化的

我有以下代码来序列化查询集;

def render_to_response(self, context, **response_kwargs):

    return HttpResponse(json.simplejson.dumps(list(self.get_queryset())),
                        mimetype="application/json")
Run Code Online (Sandbox Code Playgroud)

以下是我的 get_querset()

[{'product': <Product: hederello ()>, u'_id': u'9802', u'_source': {u'code': u'23981', u'facilities': [{u'facility': {u'name': {u'fr': u'G\xe9n\xe9ral', u'en': u'General'}, u'value': {u'fr': [u'bar', u'r\xe9ception ouverte 24h/24', u'chambres non-fumeurs', u'chambres familiales',.........]}]
Run Code Online (Sandbox Code Playgroud)

我需要序列化.但它说不能序列化<Product: hederello ()>.因为列表由django对象和dicts组成.有任何想法吗 ?

python django serialization json django-class-based-views

81
推荐指数
7
解决办法
13万
查看次数