python 和 Pyramid 的新手。
我有一个分页视图。我如何对其进行 json 编码?当我尝试这个时,我得到一个错误“0x2d16d90> 的对象不是 JSON 可序列化的”:
@view_config(route_name="paginate")
def paginate(request):
query = DBSession.query(MyTable)
page_url = paginate.PageURL_WebOb(request)
customers = paginate.Page(query,
page=int(request.params.get("page", 1)),
items_per_page=25,
url=page_url)
if "partial" in request.params:
# Render the partial list page
return render_to_response("templates/my_json.jinja2",
{"customers": json.dumps(customers)},
request=request)
else:
# Render the full list page
return render_to_response("templates/my.jinja2",
{"customers": customers},
request=request)