有没有办法用 json(或除了渲染之外的任何东西)发送一个用分页器制作的 object_list 吗?浏览器正在发出 getjson jquery 请求,views.py 函数应该返回该对象。我想返回一个 json 对象而不是渲染一个新页面的原因是因为我不希望页面重新加载
以下views.py代码:
searchresults = form.search()#this is a call to a haystack form template
results = Paginator(searchresults, 20)
page = results.page(1)
return HttpResponse(json.dumps(page), content_type='application/json')
得到这个错误:
TypeError: <Page 1 of 1> is not JSON serializable