我正在尝试查询数据列表,将其转换为 json 对象,然后将其传递给我的 javascript,以便可以在那里对其进行评估:
var data = '{{ passed_list|jsonify }}';
# This evaluates to:
var news = '[{"pk": 133, "model": "Article.article
","fields":
但是,这不起作用,因为我正在尝试访问元素。
例如,
var object = data[0].pk;
In my view source, this does not evaluate to 133 as expected but it evaluates
to ... data[0].pk ... which is a bit confusing.
这是我的jsonify:
if isinstance(object, QuerySet):
return serialize('json', object)
return simplejson.dumps(object, ensure_ascii=False)
任何帮助将不胜感激,谢谢。