PYTHON
分页及查询功能
1、分页模块
下面展示一些 分页模块
。
安装分页模块:
pip install django-pure-pagination
setting.py 设置
PAGINATION_SETTINGS = {
'PAGE_RANGE_DISPLAYED': 5,
'MARGIN_PAGES_DISPLAYED': 1,
'SHOW_FIRST_PAGE_WHEN_INVALID': True,
}
分页模块调用
from pure_pagination import Paginator,EmptyPage,PageNotAnInteger
view.py
try:
'''读取所有快递信息数据以ID倒序排序'''
emsdatas = emsdata.objects.all().order_by('-id')
'''分页'''
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
p = Paginator(emsdatas, 15, request=request)
ems = p.page(page)
context = {
'ems':ems}
return render(request,'dataview/index.html',context)
index.html
<div>
<ul class="pagination pull-right">
{
% if ems.has_previous %}
<li class="long"><a
href="?{
{ ems.previous_page_number.querystring }}">上一页</a>
</li