Zey*_*nel 4 python google-app-engine pagination cursor
谁能指点我cursor()做分页的实际应用?
我不清楚如何使用文档中cursor()给出的.
这是我的查询:
items = db.GqlQuery("SELECT * FROM Item ORDER BY date DESC LIMIT 30")
Run Code Online (Sandbox Code Playgroud)
我这样渲染:
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>")
Run Code Online (Sandbox Code Playgroud)
谢谢!
UPDATE
嗨Amir:谢谢你的回答,但我不能让这个链接工作.这就是我所拥有的:
#===========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))
Run Code Online (Sandbox Code Playgroud)
但是这导致这个url没有显示任何内容:
http://localhost:8083/dir?type=newest?cursor=E9oBdgoTc2FyYWgtZm9yLXByZXNpZGVudBoESXRlbUtSBGRhdGVYAkwhQ1VSU09SIWoiahNzYXJhaC1mb3ItcHJlc2lkZW50cgsLEgRJdGVtGKsCDHIVCAcaBGRhdGUgACoJCMid8OXW4qYCggELCxIESXRlbRirAgzgAQAU
Run Code Online (Sandbox Code Playgroud)
更新2
请参阅下面的@Amir评论:更改第二个?以&解决问题.谢谢!
这是一个让你入门的简单例子......
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2497 次 |
| 最近记录: |