django -- 内置分页

from django.conf.urls import url
from conn_oracle import views

urlpatterns = [

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')
        contacts =
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        contacts =
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        contacts =

    return render(request, 'page.html', {'contacts': contacts})

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'


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <h1 class="i1">Info of USERS</h1>

    <table class="i1" border = 1px cellpadding="5">
            {% for item in contacts %}
                    <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>
            {% endfor %}

    <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 }}.

            {% if contacts.has_next %}
                <a href="?page={{ contacts.next_page_number }}">next</a>
            {% endif %}