本文仅作为个人在Django结合Bootstrap分页显示mysql中的编程记录。

文件目录


以下文件放在Djiango的默认存储位置

views.py

def cmdb(request):#取数据库所有值userdb = models.user_table.objects.all()stu = models.userip_info.objects.all()#stu的分页数量page = Paginator(stu, 8)#获取当前所需的分页数值page_id = request.GET.get('page_id')print(page_id)if page_id:try:stus = page.page(page_id)except PageNotAnInteger:stus = page.page(1)except EmptyPage:stus = page.page(1)else:stus = page.page(1)#默认为页码1return render(request, 'cmdb.html', locals()) #传参到cmdb.html

cmdb.html

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CMDB系统</title>
<link href="{% static 'cmdb/bootstrap-3.4.1-dist/css/bootstrap.min.css' %}" rel="stylesheet" /><script src="{% static 'cmdb/js/jquery.min.js' %}"></script><script src="{% static 'cmdb/bootstrap-3.4.1-dist/js/bootstrap.min.js' %}"></script>{#    bootstrap-table 插件#}<link href="{% static 'cmdb/bootstrap-table-master/dist/bootstrap-table.min.css' %}" rel="stylesheet"/><script src="{% static 'cmdb/bootstrap-table-master/dist/bootstrap-table.min.js' %}"></script><script src="{% static 'cmdb/bootstrap-table-master/dist/locale/bootstrap-table-zh-CN.min.js' %}"></script><script type="text/javascript" src="{% static 'cmdb/jquery.min.js' %}"></script><link rel="stylesheet" href="../static/cmdb/css/style.css" type="text/css" />
<style>* {margin: 0;padding: 0;}body {font: 14px/1.4 "Microsoft Yahei", Tahoma,Georgia, Serif;}#page-wrap {margin: 10px;}p {margin: 20px 0;}/*Generic Styling, for Desktops/Laptops*/table {width: 100%;border-collapse: collapse; background:#fff}/* Zebra striping */tr:nth-of-type(odd) {background: #eee;}th {background: #333;color: white;font-weight: bold;}td, th {padding: 6px;border: 1px solid #ccc;text-align: center;}@mediaonly screen and (max-width: 760px),(min-device-width: 768px) and (max-device-width: 1024px)  {/* Force table to not be like tables anymore */table, thead, tbody, th, td, tr {display: block;}/* Hide table headers (but not display: none;, for accessibility) */thead tr {position: absolute;top: -9999px;left: -9999px;}tr { border: 1px solid #ccc; }td {/* Behave  like a "row" */border: none;border-bottom: 1px solid #eee;position: relative;padding-left: 50%;}td:before {/* Now like a table header */position: absolute;/* Top/left values mimic padding */top: 6px;left: 6px;width: 45%;padding-right: 10px;white-space: nowrap;}/*Label the data*/}/* Smartphones (portrait and landscape) ----------- */@media only screenand (min-device-width : 320px)and (max-device-width : 480px) {body {padding: 0;margin: 0;  }}/* iPads (portrait and landscape) ----------- */@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {body {width: 100%;}}</style><!--<![endif]-->
</head>
<body>
<div class="body_con"><div class="body_top">CMDB系统</div><div class="body_con_div"><div class="body_left"><ul><div class="body_right"><div ><br><h3>所有信息</h3><div id="page-wrap"style="margin:20px 0 0"><table ><thead >{% for data1 in userdb %}<tr><th width="50">{{data1.id}}</th><th width="80">{{data1.table_name}}</th><th width="130">{{data1.table_id}}</th><th width="150">{{data1.table_mac}}</th><th>{{data1.table_sw}}</th><th>{{data1.table_lable}}</th><th>{{data1.table_document}}</th><th>{{data1.table_iprange}}</th><th>{{data1.table_building}}</th><th>{{data1.table_floor}}</th></tr>{% endfor %}</thead><tbody>{% for data in stus %}<tr><td>{{data.id}}</td><td>{{data.table_name}}</td><td>{{data.table_id}}</td><td>{{data.table_mac}}</td><td>{{data.table_sw}}</td><td>{{data.table_lable}}</td><td>{{data.table_document}}</td><td>{{data.ip_range}}</td><td>{{data.table_building}}</td><td>{{data.table_floor}}</td></tr>{% endfor %}</tbody></table></div><nav aria-label="Page navigation">
<ul class="pagination">{# stus.has_previous指前一个界面 #}{% if stus.has_previous %}<li><a href="/cmdb?page_id={{stus.previous_page_number}}">&laquo;</a></li>{% endif %}{#page.page_range 所有的数据自动分页数量#}
{% for i in page.page_range %}{#  stus.number 是当前页面  #}{% if stus.number == i %}
{#   stus.number == i符合要求则分页数目为激活状态  #}<li class="active"><a href="/cmdb?page_id={{i}}">{{i}}</a></li>{% else %}{#  无激活状态  #}<li><a href="/cmdb?page_id={{i}}">{{i}}</a></li>{% endif %}
{% endfor %}{#stus.has_next 后一个页面#}
{% if stus.has_next %}<li><a href="/cmdb?page_id={{stus.next_page_number}}" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>
{% endif %}</ul>
</nav></div></div></div>
</div>
<script src="../static/cmdb/js/style.js"></script>
</body>
</html>

urls.py

"""myweb URL ConfigurationThe `urlpatterns` list routes URLs to views. For more information please see:https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views1. Add an import:  from my_app import views2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views1. Add an import:  from other_app.views import Home2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf1. Import the include() function: from django.urls import include, path2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from login import views
urlpatterns = [path('admin/', admin.site.urls),path(r'cmdb',views.cmdb),
]

Django结合Bootstrap分页显示mysql中的值相关推荐

  1. mysql中CONCAT值为空的问题解决办法

    mysql中CONCAT值为空的问题解决办法 参考文章: (1)mysql中CONCAT值为空的问题解决办法 (2)https://www.cnblogs.com/fogwang/p/5536897. ...

  2. Eclipse搭建SSH环境实现Struts2分页显示mysql数据库表中内容

    2019独角兽企业重金招聘Python工程师标准>>> 摘要 学习(Eclipse搭建SSH(Struts2+Spring3+Hibernate3)框架项目教程),尝试搭建ssh框架 ...

  3. eclipse ssh mysql数据库_Eclipse搭建SSH环境实现Struts2分页显示mysql数据库表中内容...

    摘要 因运行后404错误,遂选择集成好SSH框架的MyEclipse开发工具: 最终实现了Struts2框架的分页查看学员信息,Spring3和Hibernate3的尝试宣告失败. 1.本项目的环境 ...

  4. MySQL_(Java)分页查询MySQL中的数据

    MySQL_(Java)使用JDBC向数据库发起查询请求 传送门 MySQL_(Java)使用JDBC创建用户名和密码校验查询方法 传送门 MySQL_(Java)使用preparestatement ...

  5. MySQL从入门到精通50讲(十)-MySQL中null值如何处理

    MySQL NULL 值处理 我们已经知道MySQL使用 SQL SELECT 命令及 WHERE 子句来读取数据表中的数据,但是当提供的查询条件字段为 NULL 时,该命令可能就无法正常工作. 为了 ...

  6. mysql alter auto increment_修改mysql中Auto_increment值的例子

    要求: 修改mysql中某张表的下一条记录的Auto_increment值. 操作方法: 查看db.table表的下一条记录auto_increment的值: show table status fr ...

  7. mysql中null值求和_sql求和涉及到null值

    SQL ISNULL().NVL().IFNULL() 和 COALESCE() 函数 请看下面的 "Products" 表: P_Id ProductName UnitPrice ...

  8. PHP + MySQL 学习笔记(三)--- 分页显示 MySQL 资料表,使用 PHP 程式做分页 page 画面输出,PHP\HTML\MySQL 的穿插使用

    我在 "PHP + MySQL 学习笔记(一)- 延续前期 HTML + CSS 规划 插入 PHP 程式做画面输出" 这篇笔记里做了一个卜卦的 HTML 画面,也做了一个 MyS ...

  9. mysql中字典值怎么添加_插入Python字典中的值,包括MySQL的键

    我有以下字典:{ '': ['0', '9'], '3904': ['playback_error', '87'], '3808': ['playback_error', '24'], '3902': ...

  10. MySQL中Cardinality值的介绍

    1)         什么是Cardinality 不是所有的查询条件出现的列都需要添加索引.对于什么时候添加B+树索引.一般的经验是,在访问表中很少一部分时使用B+树索引才有意义.对于性别字段.地区 ...

最新文章

  1. P3175 [HAOI2015]按位或(Min - Max容斥,FMT,概率期望,全网最清晰的题解!)
  2. 全文搜索引擎Elasticsearch,这篇文章给讲透了
  3. 和ISP合作需要了解什么?—Vecloud微云
  4. 【转】窗口之间的主从关系与Z-Order
  5. html留言回复评论页面模板,HTML5实现留言和回复的页面样式
  6. 2021年度618品牌营销分析报告
  7. Docker安装及配置镜像加速器
  8. 我的JavaWeb学习1
  9. android+获取图库图片+4.4,Android 从 Android 本地图库选择多个图片
  10. SQL Server-【知识与实战VII】存储过程(上)
  11. C# 虹软离线SDK引擎 人脸识别
  12. 西门子PLC usb编程电缆驱动
  13. js读取本地excel到html,JS读取本地EXCEL文件
  14. 2020央行全面降准,货币政策操作仍有较大空间
  15. IP Forwarding打开
  16. 【DevOps实战|基于Jenkins与Gitlab构建企业级持续集成环境系统】(Jenkins+Gitlab+Keepalived+Haproxy+Sonarqube+Http+灰度自动部署)
  17. MAC搭建Github/Vim看代码环境
  18. 惠普服务器dl388g7光盘引导,hp dl388g7 无光驱怎么安装系统
  19. 双模控制器很耗电_双模电动车控制器主要功能
  20. 福昕pdf阅读器的划词翻译功能如何添加(图文并茂)

热门文章

  1. 软件测试2019:第八次作业—— 缺陷管理(含缺陷管理工具的配置实验)
  2. Python04,变量与赋值
  3. FT5X06 如何应用在10寸电容屏
  4. ZOJ - 2402 DP方案数
  5. 笨鸟先飞之ASP.NET MVC系列之过滤器(04认证过滤器)
  6. URAL - 1153 Supercomputer 大数开方
  7. 另类多线程生产者与消费者模式
  8. MySQL常用系统表
  9. Jug 并行处理框架
  10. git stash (保存当前的工作现场)