前端代码:
<div class="xianshi"> {% for i in info %} <ul> <li>{{ i }}</li> </ul> {% endfor %} </div> <div class="yema"> {% for x in yemalist%} <span>{{ x | safe}}</span> {% endfor%} </div>
分页函数代码:
def text(yema, count, data): start = count * (int(yema) - 1) end = count * int(yema) info = data[start:end] if divmod(len(data), count)[1] != 0: s = divmod(len(data), count)[0] + 2 else: s = divmod(len(data), count)[0] + 1 yema_list = [] for i in range(1, s): i2 = "<a href=‘/display-%s‘>%s</a>" % (i, i) yema_list.append(i2) if int(yema)==1: xy = "<a href=‘/display-%s‘>下一页</a>" % (int(yema) + 1) yema_list.append(xy) elif 2<=int(yema)<=(s-2): sy = "<a href=‘/display-%s‘>上一页</a>"% (int(yema)-1) xy = "<a href=‘/display-%s‘>下一页</a>" % (int(yema) + 1) yema_list.insert(0,sy) yema_list.append(xy) elif int(yema)==(s-1): sy = "<a href=‘/display-%s‘>上一页</a>" % 1 # xy = "<a href=‘/display-%s‘>下一页</a>" %(s-1) yema_list.insert(0, sy) # yema_list.append(xy) return {‘info‘: info, "yemalist": yema_list}
后台代码:引入函数,赋值,返回参数即可
测试:
原文地址:https://www.cnblogs.com/Anec/p/9961273.html
时间: 2024-10-10 04:29:29