Python之django自带的分页功能
前端页面:
<div class="col-sm-6">
<div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
<ul class="pagination">
{% if tdata.has_previous %}
<li class="paginate_button previous " aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">
<a href="?page={{ tdata.previous_page_number }}">上一页</a>
</li>
{% else %}
<li class="paginate_button previous disabled " aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">
<a>上一页</a>
</li>
{% endif %}
{% for page in tdata.paginator.page_range %}
{% limit_page tdata.number page %}
{% endfor %}
{% if tdata.has_next %}
<li class="paginate_button previous " aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">
<a href="?page={{ tdata.next_page_number }}">下一页</a>
</li>
{% else %}
<li class="paginate_button previous disabled " aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">
<a>下一页</a>
</li>
{% endif %}
</ul>
</div>
</div>
templatetag
from django import template
from django.utils.html import format_html
register = template.Library()
@register.simple_tag
def limit_page(current_page, pg):
scope = abs(current_page - pg)
if scope < 3:
if current_page == pg:
page_re = """<li class="paginate_button previous active"
aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">
<a > %s </a>
</li>""" % pg
else:
page_re = """<li class="paginate_button previous "
aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">
<a href="?page= %s "> %s </a>
</li>""" % (pg, pg)
return format_html(page_re)
else:
return ""
views:
from django.core.paginator import Paginator
from django.core.paginator import EmptyPage
from django.core.paginator import PageNotAnInteger
def page_t(request):
page = request.GET.get("page")
tdata = models.Tpage.objects.all()
paginator = Paginator(tdata, 2) # 每页多少条数据
try:
tdata = paginator.page(page) # 返回 page(页数)的数据
except PageNotAnInteger:
tdata = paginator.page(1) # 第一页
except EmptyPage:
tdata = paginator.page(paginator.num_pages) # 最后一页
return render(request, "table.html", {"tdata": tdata})
Python之django自带的分页功能的更多相关文章
- django rest framework实现分页功能
在web开发中很多需求都需要实现分页功能,然而 Django Rest Framework 自带的分页功能,只能在 mixins.ListModelMixin and generics.Generic ...
- Ecmall系统自带的分页功能
在Ecmall的二次开发中,分页是必不可少的.这个系统已经自带了分页功能,下面来看看如何使用这个分页. 下面是一个自定义的类,用于查看订单的详细情况.关键在于get_order_data()这个方法, ...
- django高级应用(分页功能)
django高级应用(分页功能) 1.原生分页应用 前端html代码 <!DOCTYPE html> <html lang="en"> <head&g ...
- django内置的分页功能
django内置的分页功能 # 先导入需要查询的模型类 from game.models import Score # 导入内置的分页功能 from django.core.paginator imp ...
- django中如何实现分页功能
1.在html页面中导入js文件和css文件 <link rel="stylesheet" href="../../../static/css/jquery.pag ...
- Django【进阶】分页功能Pagination
项目中,我们需要很多非业务逻辑的功能,例如分页功能,而且此类功能移植性很好,可以在不同的项目中使用,所以整理好这些功能会一定程度上提高开发效率,下面是分页功能代码,使用时,可单独放在utils目录 & ...
- python django 之 django自带的分页
1. 例1: 基础的分页 1). vim app01/views.py def users(request): from django.core.pagina ...
- GridView自带的分页功能实现
要实现GrdView分页的功能操作如下:1.更改GrdView控件的AllowPaging属性为true.2.更改GrdView控件的PageSize属性为 任意数值(默认为10)3.更改GrdVie ...
- Ecmall系统自带的分页功能使用
在控制器如果没有定义相关模型,直接使用sql语句的话,直接使用如下语句. 即: public $db; $this->db = &db(); //然后开始使用分页类 $sql='sele ...
随机推荐
- ARM体系结构和汇编指令
第一节 可编程器件的编程原理 1. 可编程器件的特点 1 . CPU在固定频率的时钟控制下节奏运行 2 . CPU可以通过总线读取外部存储设备中的二进制指令集,然后解码执行 3 . 这些可以被CPU解 ...
- js判断移动端页面按home键切换到桌面事件
---恢复内容开始--- 原理就是通过页面标签切换事件(visibilitychange)来判断,亦可用户移动端桌面和app切换. 先看代码: var hiddenProperty = 'hidden ...
- Automate the Sizing of your SGA in Oracle 10g
How much memory does each of the individual components of the SGA need? Oracle now has methods to de ...
- SQLSERVER:PREEMPTIVE_OS_GETPROCADDRESS等待类型的困惑
SQLSERVER:PREEMPTIVE_OS_GETPROCADDRESS等待类型的困惑 翻译自:http://troubleshootingsql.com/2011/07/20/preemptiv ...
- 转:c# WinForm开发 DataGridView控件的各种操作总结(单元格操作,属性设置)
一.单元格内容的操作 *****// 取得当前单元格内容 Console.WriteLine(DataGridView1.CurrentCell.Value); // 取得当前单元格的列 Index ...
- 更新tableView的某个cell
更新tableView的某个cell 异步加载完数据后更新某个cell,这应该是非常常见的使用方法了,我们经常会用reloadData. 效果: 源码: // // RootViewControlle ...
- Stored Properties 与 Computed Properties
Stored Properties 与 Computed Properties About Swift Stored Properties In its simplest form, a stored ...
- Linux学习---Linux用户审计简单版
[root@localhost root]# vim /etc/profile # SHENJI history USER=`whoami` USER_IP=`who -u am i 2>/de ...
- Nginx 泛解析配置请求映射到多端口实现二级域名访问
由于想实现一个域名放置多个应用运行的目的,而不想通过域名后加端口号方式处理,这种方式处理记起来太麻烦,偷懒党简直不能忍,故而考虑了使用二级域名来处理多个应用同时运行.Google了一番资料并进行了尝试 ...
- (转)图形学理论知识 BRDF 双向反射分布函数(Bidirectional Reflectance Distribution Function)
BRDF理论 BRDF表示的是双向反射分布函数(Bidirectional Reflectance Distribution Function),它描述了光线如何在物体表面进行反射,可以用来描述材质属 ...