本文介绍了如何使用cursor()分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以指点一个实际的应用程序 cursor()
做分页吗?
我不清楚如何使用。
这是我的查询:
items = db.GqlQuery SELECT * FROM Item ORDER BY date DESC LIMIT 30)
p>
self.response.out.write(< ol>)
项目中的项目:
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点%s由%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& )
谢谢!
UPDATE
Hi Amir:感谢您的回答,但我无法使此链接生效。这里是我有:
#===========在这里添加光标====== =====#
cursor = self.request.get(cursor)
如果cursor:query.with_cursor(cursor)
items = query.fetch(30)
cursor = query.cursor()
#===========在此处添加光标===========#
#=========== regular output ===========#
self.response.out.write(< ol>)
项目中的项目:
self.response.out.write(< li>
< a href =/ vote /%s?type =%s> ^< / a>< a href =%s>
< span id =large>%s< / span>< / a>
< span id = '>(%s)< / span>
< br />
%s< br />< span id ='Small'>
% %s由%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,
.summary,item.points,item.date.strftime(%B%d,%Y%I:%M%p),
item.user_who_liked_this_item,str(item.key ),
str(item.key().id()))
self.response.out.write(< / ol>)
# ==========常规输出===========#
#===========链接到游标=== ========#
self.response.out.write(< a href =/ dir?type =%s?cursor =%s> Next
Page< / a>%(merchandise_type,cursor))
这显示没有:
的http://本地主机:?8083 / DIR类型=最新光标= E9oBdgoTc2FyYWgtZm9yLXByZXNpZGVudBoESXRlbUtSBGRhdGVYAkwhQ1VSU09SIWoiahNzYXJhaC1mb3ItcHJlc2lkZW50cgsLEgRJdGVtGKsCDHIVCAcaBGRhdGUgACoJCMid8OXW4qYCggELCxIESXRlbRirAgzgAQAU
更新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()
...您的常规输出...
self.response.out.write('< a href =yoururl?cursor =%s>下一页< / a>'%cursor)
Can anyone point me to a practical application of
cursor()
to do pagination?I am not clear how to use
cursor()
as given in the documentation.This is my query:
items = db.GqlQuery("SELECT * FROM Item ORDER BY date DESC LIMIT 30")
which I render like this:
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>")
Thanks!
UPDATE
Hi Amir: Thanks for your answer but I could't make this link work. Here's what I have:
#===========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))
But this results in this url which displays nothing:
http://localhost:8083/dir?type=newest?cursor=E9oBdgoTc2FyYWgtZm9yLXByZXNpZGVudBoESXRlbUtSBGRhdGVYAkwhQ1VSU09SIWoiahNzYXJhaC1mb3ItcHJlc2lkZW50cgsLEgRJdGVtGKsCDHIVCAcaBGRhdGUgACoJCMid8OXW4qYCggELCxIESXRlbRirAgzgAQAU
Update 2
See @Amir comment below: changing the second
?
to&
solved the problem. Thanks!解决方案Here's a simple example to get you started...
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)
这篇关于如何使用cursor()分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!