django viewList 中实现分页功能

来源:互联网 发布:矩阵防御 编辑:程序博客网 时间:2024/05/16 12:57

views.py:

from django.shortcuts import renderfrom django.views.generic import   ListViewfrom .models import AttendanceList# Create your views here.class AttendanceListIndex(ListView):    context_object_name = 'attendanceListlist'    template_name = 'attendance/Node/index.html'    paginate_by = 1  #每页显示的条目数    model =AttendanceList

工程url.py:

from django.conf.urls import url,includefrom django.contrib import adminurlpatterns = [    url(r'^admin/', admin.site.urls),    url(r'^attendance/', include('attendance.urls')),]


app 中url.py :

from django.conf.urls import urlfrom django.views.generic import TemplateViewfrom views import AttendanceListIndexurlpatterns = [    url(r'^index/$', TemplateView.as_view(template_name="attendance/index.html")),    url(r'^Node/index.html/$',AttendanceListIndex.as_view(),name='showattendance')]


attendance/Node/index.html:
{% if is_paginated %}    <div class="pagination">        <span class="page-links">            {% if page_obj.has_previous %}                <a href="/attendance/Node/index.html/?page={{ page_obj.previous_page_number }}">上一页</a>            {% endif %}            {% if page_obj.has_next %}                <a href="/attendance/Node/index.html/?page={{ page_obj.next_page_number }}">下一页</a>            {% endif %}            <span class="page-current">                第{{ page_obj.number }}页 ,共{{ page_obj.paginator.num_pages }}页            </span>        </span>    </div>{% else %}<p>No msgs !!!</p>{%endif%}


0 0
原创粉丝点击