web分页处理函数实现!
今天觉得无聊,想想做点什么?就做了一个Karrigell的分页处理函数,现在共享一下,如果你有什么好建议,说一下!
import types
mydata = ['aaaa','bbbb','cccc','dddd','eeee','ffff','gggg','hhhh','iiiii','jjjj','kkkk','llll','mmmm','oooo','pppp','qqqq','rrrr']
def index(**args) :
fy(mydata)
def fy(mydata) :
num = 5 #每页纪录数
l_ys = len(mydata)/num
l_su = len(mydata)%num
if l_su > 0 : #取得页数ys
ys = l_ys + 1
else :
ys = l_ys
if QUERY.has_key('id') :
id = int(_id)
else :
id = 0
if (id>= ys) or (id < 0) :
print '没有您要的数据'
raise SCRIPT_END
if ys == 1 :
for line in mydata :
if type(line) is tuple :
for col in line :
print col
else :
print line
print '<br>'
else :
if id == 0 :
print '<a href="?id=%d">下一页</a><br>' %(id+1)
elif id == ys-1 :
print '<a href="?id=%d">上一页</a><br>' %(id-1)
else :
print '<a href="?id=%d">上一页</a>' %(id-1)
print '<a href="?id=%d">下一页</a><br>' %(id+1)
for line in mydata[num*id:num*id+num] :
if type(line) is tuple :
for col in line :
print col
else :
print line
print '<br>'