urls.py

from django.conf.urls import url
from conn_oracle import views urlpatterns = [
url(r'^page/', views.page),
]

views.py

from django.shortcuts import render
from conn_oracle import models
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger def page(request):
contact_list = models.UserRegister.objects.all()
paginator = Paginator(contact_list, 10) # Show 10 contacts per page
page = request.GET.get('page')
try:
contacts = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
contacts = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
contacts = paginator.page(paginator.num_pages) return render(request, 'page.html', {'contacts': contacts})

models.py

from django.db import models

class UserRegister(models.Model):
user_id = models.CharField(max_length=200, primary_key=True, db_column='user_id', null=True)
login_name = models.CharField(max_length=50, db_column='login_name', null=True)
user_gender = models.CharField(max_length=1, db_column='user_gender')
user_real_name = models.CharField(max_length=200)
user_hsp_name = models.CharField(max_length=300) class Meta:
db_table = 'user_register'

page.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1 class="i1">Info of USERS</h1> <table class="i1" border = 1px cellpadding="5">
<thead>
<tr>
<th>用户id</th>
<th>用户名</th>
<th>性别</th>
<th>姓名</th>
<th>单位</th>
</tr>
</thead>
<tbody>
{% for item in contacts %}
<tr>
<td>{{ item.user_id }}</td>
<td>{{ item.login_name }}</td>
<td>{{ item.user_gender }}</td>
<td>{{ item.user_real_name }}</td>
<td>{{ item.user_hsp_name }}</td>
</tr>
{% endfor %}
</tbody>
</table> <div class="pagination">
<span class="step-links">
{% if contacts.has_previous %}
<a href="?page={{ contacts.previous_page_number }}">previous</a>
{% endif %} <span class="current">
Page {{ contacts.number }} of {{ contacts.paginator.num_pages }}.
</span> {% if contacts.has_next %}
<a href="?page={{ contacts.next_page_number }}">next</a>
{% endif %}
</span>
</div> </body>
</html>

效果:

注:参考  https://docs.djangoproject.com/en/1.10/topics/pagination/

django -- 内置分页的更多相关文章

  1. Django内置分页

    一.django内置分页 from django.shortcuts import render from django.core.paginator import Paginator, EmptyP ...

  2. Django 内置分页的简单使用

    1, 文档 https://docs.djangoproject.com/en/1.11.1/topics/pagination/ 2,视图 from django.core.paginator im ...

  3. Django 内置分页--Paginator类

    官方文档 http://python.usyiyi.cn/django/topics/pagination.html 前端方法 http://www.tuicool.com/articles/RniU ...

  4. Django,ajax实现表格增删查改,Django内置分页功能。

    1.工程目录 2.urls.py """Django_ajax URL Configuration The `urlpatterns` list routes URLs ...

  5. django内置分页功能扩展

    实现自定制页码数类型class myPaginator(Paginator): def __init__(self,curr_page,per_page_num,*args,**kwargs): se ...

  6. django的内置分页

    本节内容 自定义一个简单的内置分页 Django内置分页 Django内置分页扩展(继承) 自定义内置组件 自定义一个简单的内置分页 先用django自己自定制一个简单的内置分页,大概掌握内置分页的底 ...

  7. Django内置的分页模块

    自定义分页 未封装版: 优点:直观 缺点:代码乱,不易维护,可拓展性差 data = [] for i in range(1, 302): tmp = {"id": i, &quo ...

  8. django内置的分页功能

    django内置的分页功能 # 先导入需要查询的模型类 from game.models import Score # 导入内置的分页功能 from django.core.paginator imp ...

  9. Django内置Admin

    Django内置的Admin是对于model中对应的数据表进行增删改查提供的组件,使用方式有: 依赖APP: django.contrib.auth django.contrib.contenttyp ...

随机推荐

  1. maven scope-一览表

  2. Jmeter-JDBC Connection Configuration和JDBC Request注释

    1.JDBC Connection Configuration Variable Name--变量名,唯一值不可重复,给JDBC Request确定使用哪个配置 Max Number of Conne ...

  3. Scala的=>作用

    举例: var increase = (x: Int) => x + 1 increase(10) res0: Int = 11 类似于转化符号,=>指明这个函数把左边的东西(任何整数x) ...

  4. flask第十一篇——自定义url转换器

    首先和大家说一下flask的组成,flask其实是werkzeug(路由和http处理)+SQLAlchemy(数据库)+Jinja2(模板)组成的,今天我们要看到的东西就是`werkzeug`里面的 ...

  5. bat命令2

    echo.@.call.pause.rem(小技巧:用::代替rem)是批处理文件最常用的几个命令,我们就从他们开始学起. echo 表示显示此命令后的字符 echo off 表示在此语句后所有运行的 ...

  6. docker swarm mode routing mesh 使用

    Docker Engine swarm mode makes it easy to publish ports for services to make them available to resou ...

  7. php、打印

    <!DOCTYPE HTML><html><head><meta http-equiv="content-type" content=&q ...

  8. python 与时间有关的操作

    python保存时间戳文件 import time # ISOTIMEFORMAT='%Y-%m-%d %X' ISOTIMEFORMAT='%Y-%m-%d' t= time.strftime( I ...

  9. zk中文乱码问题

    之前讲了怎么把数据导入到zookeeper(见zookeeper事件监听的importData方法),虽然本机win10的zookeeper展示没问题,但到了linux上就出现乱码了: << ...

  10. Linux GNU C

    Linux 系统上可用的C编译器是GNU C编译器,它建立在自由软件基金会的编程许可证的基础上,因此可以自由发布.GNU C对标准C 进行一系列扩展,以增强标准C的功能. 1.零长度数组GNU C 允 ...