gpt4 book ai didi

python - 如何使用 cursor() 进行分页?

转载 作者:太空狗 更新时间:2023-10-30 02:23:17 26 4
gpt4 key购买 nike

谁能告诉我 cursor() 进行分页的实际应用?

我不清楚如何使用 documentation 中给出的 cursor() .

这是我的查询:

items = db.GqlQuery("SELECT * FROM Item ORDER BY date DESC LIMIT 30")

我这样渲染:

self.response.out.write("<ol>")
for item in items:
self.response.out.write("""<li><a href="/vote/%s?type=%s"> ^ </a><a href="%s">%s</a> <span id='Small'>(%s)</span><br />
<div id='Small'>
%s points %s by %s <a href="/item/%s"></a> |
<a href="/item/%s#disqus_thread"></a></div>
</li><br /> """ %
(str(item.key().id()), merchandise_type, item.url, item.title, urlparse(item.url).netloc,
item.points, item.date.strftime("%B %d, %Y %I:%M%p"), item.user_who_liked_this_item, str(item.key().id()), str(item.key().id())))

self.response.out.write("</ol>")

谢谢!

更新

您好阿米尔:感谢您的回答,但我无法使此链接有效。这是我拥有的:

#===========adding cursor here===========#
cursor = self.request.get("cursor")
if cursor: query.with_cursor(cursor)
items = query.fetch(30)
cursor = query.cursor()

#===========adding cursor here===========#

#===========regular output===========#
self.response.out.write("<ol>")
for item in items:
self.response.out.write("""<li>
<a href="/vote/%s?type=%s"> ^ </a><a href="%s">
<span id="large">%s</span></a>
<span id='Small'>(%s)</span>
<br />
%s<br /> <span id='Small'>
%s points %s by %s <a href="/item/%s"></a> |
<a href="/item/%s#disqus_thread"></a>
</span>
</li><br /> """ %
(str(item.key().id()), merchandise_type, item.url,
item.title, urlparse(item.url).netloc,
item.summary, item.points, item.date.strftime("%B %d, %Y %I:%M%p"),
item.user_who_liked_this_item, str(item.key().id()),
str(item.key().id())))

self.response.out.write("</ol>")
#===========regular output===========#

#===========link to cursor===========#
self.response.out.write("""<a href="/dir?type=%s?cursor=%s">Next
Page</a>""" % (merchandise_type, cursor))

但这会导致此 url 不显示任何内容:

http://localhost:8083/dir?type=newest?cursor=E9oBdgoTc2FyYWgtZm9yLXByZXNpZGVudBoESXRlbUtSBGRhdGVYAkwhQ1VSU09SIWoiahNzYXJhaC1mb3ItcHJlc2lkZW50cgsLEgRJdGVtGKsCDHIVCAcaBGRhdGUgACoJCMid8OXW4qYCggELCxIESXRlbRirAgzgAQAU

最佳答案

这是一个让您入门的简单示例...

query = db.GqlQuery("SELECT * FROM Item ORDER BY date DESC")
cursor = self.request.get('cursor')
if cursor: query.with_cursor(cursor)
items = query.fetch(30)
cursor = query.cursor()

... your regular output ...

self.response.out.write('<a href="yoururl?cursor=%s">Next Page</a>' % cursor)

关于python - 如何使用 cursor() 进行分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4840731/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com