Django實(shí)現(xiàn)分頁(yè)功能
Django 分頁(yè)功能的實(shí)現(xiàn),供大家參考,具體內(nèi)容如下
創(chuàng)建項(xiàng)目創(chuàng)建APP,添加APP這些就不在多說(shuō)我們這次重點(diǎn)來(lái)看到視圖函數(shù)
下面是路由設(shè)置
視圖函數(shù)繼承TemplateView
views.py
class index4(ListView): template_name = ’index5.html’ # 設(shè)置模板文件以至于找到該模板文件 extra_context = {’title’: ’人員信息表’} # 設(shè)置響應(yīng)內(nèi)容 queryset = PersonInfo.objects.all() # 設(shè)置查詢模型查詢所有信息 paginate_by = 1 # 每頁(yè)展示的數(shù)據(jù) context_object_name = ’personInfo’ # 設(shè)置模板名稱
接下來(lái)就是HTML模板的編寫(xiě)
index5.py
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>{{ title }}</title></head><body><h1>{{ title }}</h1><table border='8'> {% for i in personInfo %} <tr> <th>{{ i.name }}</th> <th>{{ i.age }}</th> </tr> {%endfor%}</table><br>{% if is_paginated %}<div class='pagination'> <span class='page-links'> {% if page_obj.has_previous %} <a href='http://www.cgvv.com.cn/?page={{ page_obj.previous_page_number }}' >上一頁(yè)</a> {% endif %} {% if page_obj.has_next %} <a href='http://www.cgvv.com.cn/?page={{ page_obj.next_page_number }}' >下一頁(yè)</a> {% endif %} <br> <br> <span class='page-current'> 第{{ page_obj.number }}頁(yè) 共{{ page_obj.paginator.num_pages }}頁(yè) </span> </span></div>{% endif %}</body></html>
運(yùn)行功能圖片
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 在idea中為注釋標(biāo)記作者日期操作2. Python中讀取文件名中的數(shù)字的實(shí)例詳解3. python中scrapy處理項(xiàng)目數(shù)據(jù)的實(shí)例分析4. ajax動(dòng)態(tài)加載json數(shù)據(jù)并詳細(xì)解析5. ASP.Net Core對(duì)USB攝像頭進(jìn)行截圖6. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢、排序、分頁(yè)7. 使用AJAX(包含正則表達(dá)式)驗(yàn)證用戶登錄的步驟8. JSP頁(yè)面的靜態(tài)包含和動(dòng)態(tài)包含使用方法9. 通過(guò)Ajax方式綁定select選項(xiàng)數(shù)據(jù)的實(shí)例10. .net如何優(yōu)雅的使用EFCore實(shí)例詳解
