最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python Django實(shí)現(xiàn)layui風(fēng)格+django分頁(yè)功能的例子

 更新時(shí)間:2019年08月29日 16:30:21   作者:Luzaofa  
今天小編就為大家分享一篇Python Django實(shí)現(xiàn)layui風(fēng)格+django分頁(yè)功能的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

第一步:首先定義一個(gè)視圖函數(shù),用于提供數(shù)據(jù),實(shí)現(xiàn)每頁(yè)顯示數(shù)據(jù)個(gè)數(shù),返回每頁(yè)請(qǐng)求數(shù)據(jù)

from django.shortcuts import render
from django.core.paginator import Paginator # Django內(nèi)置分頁(yè)功能模塊

def index(request):
 # 提供json數(shù)據(jù)
 resp = {"id":10000,"username":"user-0","sex":"女","city":"城市-0","sign":"簽名-0","experience":255,"logins":24,"wealth":82830700,"classify":"作家","score":57},{"id":10001,"username":"user-1","sex":"男","city":"城市-1","sign":"簽名-1","experience":884,"logins":58,"wealth":64928690,"classify":"詞人","score":27},{"id":10002,"username":"user-2","sex":"女","city":"城市-2","sign":"簽名-2","experience":650,"logins":77,"wealth":6298078,"classify":"醬油","score":31},{"id":10003,"username":"user-3","sex":"女","city":"城市-3","sign":"簽名-3","experience":362,"logins":157,"wealth":37117017,"classify":"詩(shī)人","score":68},{"id":10004,"username":"user-4","sex":"男","city":"城市-4","sign":"簽名-4","experience":807,"logins":51,"wealth":76263262,"classify":"作家","score":6},{"id":10005,"username":"user-5","sex":"女","city":"城市-5","sign":"簽名-5","experience":173,"logins":68,"wealth":60344147,"classify":"作家","score":87},{"id":10006,"username":"user-6","sex":"女","city":"城市-6","sign":"簽名-6","experience":982,"logins":37,"wealth":57768166,"classify":"作家","score":34},{"id":10007,"username":"user-7","sex":"男","city":"城市-7","sign":"簽名-7","experience":727,"logins":150,"wealth":82030578,"classify":"作家","score":28},{"id":10008,"username":"user-8","sex":"男","city":"城市-8","sign":"簽名-8","experience":951,"logins":133,"wealth":16503371,"classify":"詞人","score":14},{"id":10009,"username":"user-9","sex":"女","city":"城市-9","sign":"簽名-9","experience":484,"logins":25,"wealth":86801934,"classify":"詞人","score":75},{"id":10010,"username":"user-10","sex":"女","city":"城市-10","sign":"簽名-10","experience":1016,"logins":182,"wealth":71294671,"classify":"詩(shī)人","score":34},{"id":10011,"username":"user-11","sex":"女","city":"城市-11","sign":"簽名-11","experience":492,"logins":107,"wealth":8062783,"classify":"詩(shī)人","score":6},{"id":10012,"username":"user-12","sex":"女","city":"城市-12","sign":"簽名-12","experience":106,"logins":176,"wealth":42622704,"classify":"詞人","score":54},{"id":10013,"username":"user-13","sex":"男","city":"城市-13","sign":"簽名-13","experience":1047,"logins":94,"wealth":59508583,"classify":"詩(shī)人","score":63},{"id":10014,"username":"user-14","sex":"男","city":"城市-14","sign":"簽名-14","experience":873,"logins":116,"wealth":72549912,"classify":"詞人","score":8},{"id":10015,"username":"user-15","sex":"女","city":"城市-15","sign":"簽名-15","experience":1068,"logins":27,"wealth":52737025,"classify":"作家","score":28},{"id":10016,"username":"user-16","sex":"女","city":"城市-16","sign":"簽名-16","experience":862,"logins":168,"wealth":37069775,"classify":"醬油","score":86},{"id":10017,"username":"user-17","sex":"女","city":"城市-17","sign":"簽名-17","experience":1060,"logins":187,"wealth":66099525,"classify":"作家","score":69},{"id":10018,"username":"user-18","sex":"女","city":"城市-18","sign":"簽名-18","experience":866,"logins":88,"wealth":81722326,"classify":"詞人","score":74},{"id":10019,"username":"user-19","sex":"女","city":"城市-19","sign":"簽名-19","experience":682,"logins":106,"wealth":68647362,"classify":"詞人","score":51},{"id":10020,"username":"user-20","sex":"男","city":"城市-20","sign":"簽名-20","experience":770,"logins":24,"wealth":92420248,"classify":"詩(shī)人","score":87},{"id":10021,"username":"user-21","sex":"男","city":"城市-21","sign":"簽名-21","experience":184,"logins":131,"wealth":71566045,"classify":"詞人","score":99},{"id":10022,"username":"user-22","sex":"男","city":"城市-22","sign":"簽名-22","experience":739,"logins":152,"wealth":60907929,"classify":"作家","score":18},{"id":10023,"username":"user-23","sex":"女","city":"城市-23","sign":"簽名-23","experience":127,"logins":82,"wealth":14765943,"classify":"作家","score":30},{"id":10024,"username":"user-24","sex":"女","city":"城市-24","sign":"簽名-24","experience":212,"logins":133,"wealth":59011052,"classify":"詞人","score":76},{"id":10025,"username":"user-25","sex":"女","city":"城市-25","sign":"簽名-25","experience":938,"logins":182,"wealth":91183097,"classify":"作家","score":69},{"id":10026,"username":"user-26","sex":"男","city":"城市-26","sign":"簽名-26","experience":978,"logins":7,"wealth":48008413,"classify":"作家","score":65},{"id":10027,"username":"user-27","sex":"女","city":"城市-27","sign":"簽名-27","experience":371,"logins":44,"wealth":64419691,"classify":"詩(shī)人","score":60},{"id":10028,"username":"user-28","sex":"女","city":"城市-28","sign":"簽名-28","experience":977,"logins":21,"wealth":75935022,"classify":"作家","score":37},{"id":10029,"username":"user-29","sex":"男","city":"城市-29","sign":"簽名-29","experience":647,"logins":107,"wealth":97450636,"classify":"醬油","score":27}
 # 每頁(yè)顯示5條數(shù)據(jù)
 paginator = Paginator(resp, 5)
 page = request.GET.get('page')
 contacts = paginator.get_page(page)
 return render(request, 'index.html', {'contacts': contacts})

第二步:前端顯示模塊(基于layui模塊),在templates目錄下新建一個(gè)index.html文件(按照自己需求在官網(wǎng)復(fù)制代碼)

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <title>翻頁(yè)</title>
 <meta name="renderer" content="webkit">
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
 <link rel="stylesheet" href="../static/layui/css/layui.css" rel="external nofollow" media="all">
</head>
<body>
<div style="width: 650px; position: relative; left:25%;">

 <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px">
  <legend>翻頁(yè)(layui風(fēng)格+django功能)</legend>
 </fieldset>
  <table class="layui-table">
  <colgroup>
   <col width="150">
   <col width="200">
   <col>
  </colgroup>
  <thead>
   <tr class="layui-bg-red">
   <th>標(biāo)題</th>
   <th>用戶(hù)名</th>
   <th>手機(jī)號(hào)碼</th>
   <th>郵箱地址</th>
   </tr>
  </thead>

  <tbody>
  {% for contact in contacts %}
  <tr>
   <td>{{ contact.id }}</td>
   <td>{{ contact.username }}</td>
   <td>{{ contact.sex }}</td>
   <td>{{ contact.experience }}</td>
   </tr>
  {% endfor %}
  </tbody>
  </table>

<script src="../static/layui/layui.js" charset="utf-8"></script>

</body>
</html>

第三步:在index.html里添加如下Django分頁(yè)功能即可:

<div class="pagination">
 <span class="step-links">
  {% if contacts.has_previous %}
   <button class="layui-btn">
    <a href="?page=1" rel="external nofollow" >第一頁(yè)</a>
   </button>

   <button class="layui-btn">
    <a href="?page={{ contacts.previous_page_number }}" rel="external nofollow" ><i class="layui-icon">&#xe65a;</i></a>
   </button>
  {% endif %}

  <span class="current">
   <button class="layui-btn">
    第 {{ contacts.number }}頁(yè) 共 {{ contacts.paginator.num_pages }}頁(yè)
   </button>
  </span>

  {% if contacts.has_next %}
   <button class="layui-btn">
    <a href="?page={{ contacts.next_page_number }}" rel="external nofollow" ><i class="layui-icon">&#xe65b;</i></a>
   </button>

   <button class="layui-btn">
    <a href="?page={{ contacts.paginator.num_pages }}" rel="external nofollow" >最后一頁(yè)</a>
   </button>
  {% endif %}
 </span>
</div>
</div>

實(shí)現(xiàn)效果圖如下:

以上這篇Python Django實(shí)現(xiàn)layui風(fēng)格+django分頁(yè)功能的例子就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python生成器定義與簡(jiǎn)單用法實(shí)例分析

    Python生成器定義與簡(jiǎn)單用法實(shí)例分析

    這篇文章主要介紹了Python生成器定義與簡(jiǎn)單用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Python生成器的概念、原理、使用方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2018-04-04
  • Python生成requirements.txt的三種方法

    Python生成requirements.txt的三種方法

    requirements.txt?文件通常用于列出項(xiàng)目所需的所有Python包及其版本,本文主要介紹了Python生成requirements.txt的三種方法,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-07-07
  • Python使用functools模塊中的partial函數(shù)生成偏函數(shù)

    Python使用functools模塊中的partial函數(shù)生成偏函數(shù)

    所謂偏函數(shù)即是規(guī)定了固定參數(shù)的函數(shù),在函數(shù)式編程中我們經(jīng)常可以用到,這里我們就來(lái)看一下Python使用functools模塊中的partial函數(shù)生成偏函數(shù)的方法
    2016-07-07
  • python命令行解析之parse_known_args()函數(shù)和parse_args()使用區(qū)別介紹

    python命令行解析之parse_known_args()函數(shù)和parse_args()使用區(qū)別介紹

    這篇文章主要介紹了python命令行解析之parse_known_args()函數(shù)和parse_args()使用介紹,需要的朋友可以參考下
    2018-01-01
  • Django?RestFramework?全局異常處理詳解

    Django?RestFramework?全局異常處理詳解

    這篇文章主要為大家詳細(xì)介紹了Django?RestFramework?全局異常處理,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-02-02
  • Python中對(duì)數(shù)據(jù)庫(kù)的操作詳解

    Python中對(duì)數(shù)據(jù)庫(kù)的操作詳解

    今天簡(jiǎn)單說(shuō)說(shuō)MySQL,我們存儲(chǔ)數(shù)據(jù),直接用本地文件即可,但是,本地文件不利于存放海量數(shù)據(jù),也不利于用程序?qū)ξ募臄?shù)據(jù)進(jìn)行查詢(xún)與管理,我們可以使用數(shù)據(jù)庫(kù)
    2023-02-02
  • pygame加載中文名mp3文件出現(xiàn)error

    pygame加載中文名mp3文件出現(xiàn)error

    本文主要介紹了pygame加載中文名mp3文件出現(xiàn)error的解決方案。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-03-03
  • 使用Python代碼實(shí)現(xiàn)對(duì)Excel單元格的鎖定

    使用Python代碼實(shí)現(xiàn)對(duì)Excel單元格的鎖定

    在Excel表格中,我們可以通過(guò)鎖定特定的單元格或區(qū)域,防止對(duì)單元格內(nèi)容進(jìn)行隨意修改,確保關(guān)鍵數(shù)據(jù)、公式或格式不被誤改,本文將介紹如何使用Python代碼來(lái)實(shí)現(xiàn)對(duì)Excel單元格的鎖定,實(shí)現(xiàn)批量操作以及自動(dòng)化,需要的朋友可以參考下
    2024-06-06
  • python中如何使用分步式進(jìn)程計(jì)算詳解

    python中如何使用分步式進(jìn)程計(jì)算詳解

    抽了點(diǎn)時(shí)間體驗(yàn)了一把python分布式進(jìn)程,有點(diǎn)像分布式計(jì)算的意思,這篇文章主要給大家介紹了關(guān)于python中如何使用分步式進(jìn)程計(jì)算的相關(guān)資料,需要的朋友可以參考下
    2019-03-03
  • 對(duì)python中dict和json的區(qū)別詳解

    對(duì)python中dict和json的區(qū)別詳解

    今天小編就為大家分享一篇對(duì)python中dict和json的區(qū)別詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12

最新評(píng)論

博爱县| 政和县| 土默特右旗| 乌拉特后旗| 罗城| 宝鸡市| 长沙县| 永福县| 东方市| 黄平县| 开阳县| 天峨县| 高雄县| 宁德市| 滦南县| 郁南县| 和林格尔县| 宁都县| 亚东县| 呼伦贝尔市| 青浦区| 东安县| 咸丰县| 厦门市| 昌都县| 南和县| 白城市| 麻江县| 航空| 丰镇市| 伊宁市| 介休市| 蓬溪县| 深州市| 都江堰市| 西昌市| 乌审旗| 邵东县| 应用必备| 永德县| 四平市|