使用Bootstrap-table创建表单,并且与flask后台进行数据交互

文章目录

  • 引用css和js
  • 使用
    • html
    • javascript
    • flask
    • mysql
  • 参考

引用css和js

Bootstrap-table为这些文件提供了 CDN 的支持,所以不需要下载.js .css文件就可以直接用了,十分方便

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css">
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.js"></script>
<!-- Latest compiled and minified Locales -->
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/locale/bootstrap-table-zh-CN.min.js"></script>

使用

html

在html上添加一行table。

<table id="table"></table>

javascript

在js里面添加:

// 获取后台数据
function MyupdateTable(evn, col_name) {var xmlhttp = new XMLHttpRequest();var json_rep;xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState == 4 && xmlhttp.status == 200){// var json_rep = xmlhttp.responseText.parseJSON();  json_rep = JSON.parse(xmlhttp.responseText)}}xmlhttp.open("GET","http://9.135.90.225:8090/getAlarmMsg?evn=" + evn + "&&col_name=" + col_name, false);xmlhttp.send();return json_rep;
}function judge_except(val) {if (val == 0) return "是";else return "否";
}
// 将json数据转成obj数组
function transData(json_rep, dataTable) {len = json_rep['len']for (var i = 0; i < len; i++) {dataTable.push({id: json_rep['id'][i],time: json_rep['date'][i],col_name: json_rep['colname'][i],actual: json_rep['actual'][i],scope: json_rep['scope'][i],if_except: judge_except(json_rep['if_except'][i])})}
}
var tke_room_nums_data = []
rep_tke_room_nums = MyupdateTable("tke","room_nums")
transData(rep_tke_room_nums, tke_room_nums_data)
// 对于表单结构、模式进行设置
$('#table').bootstrapTable({search: true,pagination: true,   //启动分页striped: true,    //设置为 true 会有隔行变色效果cache: false,                       //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)pageSize: 6,//初始页记录数sortable: true,    //排序pageList: [6,36,72,144], //记录数可选列表smartDisplay: false,    //程序自动判断显示分页信息columns: [{field: 'id',title: 'ID'}, {field: 'time',title: '时间'}, {field: 'col_name',title: '参数名'}, {field: 'actual',title: '实际值'},{field: 'scope',title: '预测范围'},{field: 'if_except',title: '是否告警'},],data: tke_room_nums_data
})

flask

在flask里添加这样的py程序

# author:hanhandi
# flask学习网址:https://www.w3cschool.cn/flask/flask_routing.html
# pymsql学习网址:
from flask import Flask, render_template, request, jsonify
import pymysql
import json
import logging
from dbutils.pooled_db import PooledDB
# 导入mylib
import sys
sys.path.append('/var/www/html/NewTest/InternShipProject/my_pylib')
from my_global_logic import adjust_table_name
from my_global_logic import Reverse
from my_sql import SELECTapp = Flask(__name__)# @app.route('/')
# def index():
#     return render_template("index.html")# 一些配置参数,需要从json文件中读取
with open("/var/www/html/NewTest/InternShipProject/middle_back_end/backend/param_config/179_frame_param_config.json",'r+') as f:load_dict = json.load(f)mapping_path = load_dict["mapping_path"]    # 机房与机器ip映射关系文件db_password = load_dict["db_password"]# 初始化日志记录文件
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
DATE_FORMAT = "%m/%d/%Y %H:%M:%S %p"
logging.basicConfig(filename = '/var/www/html/NewTest/logfiles/alarm_flask_backend.log', level = logging.WARNING, format = LOG_FORMAT, datefmt = DATE_FORMAT)# 解决跨域问题
@app.after_request
def cors(environ):environ.headers['Access-Control-Allow-Origin']='*'environ.headers['Access-Control-Allow-Method']='*'environ.headers['Access-Control-Allow-Headers']='x-requested-with,content-type'return environdef getMsg(evn, col_name):table_name = evn + "_" + col_name# 返回结果response_data = {'code': 0, 'msg': 'ok'}# 打开数据库连接db = pymysql.connect(host='localhost',user='root',password=db_password,database='alarm_msg')# 使用 cursor() 方法创建一个游标对象 cursorcursor = db.cursor()try:select_sql = "SELECT id, order_date, col_name, actual, scope_left, scope_right, if_except FROM %s order by id desc" % table_nameresult = SELECT(db, cursor, select_sql)id = []date = []colname = []actual = []scope_left = []scope_right = []scope = []if_except = []for row in result:id.append(row[0])date.append(row[1])colname.append(row[2])actual.append(row[3])scope_left.append(row[4])scope_right.append(row[5])if_except.append(row[6])for i in range(len(scope_left)):scope.append("[" + str(scope_left[i]) + ", "+ str(scope_right[i]) + "]")# 关闭数据库连接cursor.close()db.close()response_data['len'] = len(id)response_data['id'] = idresponse_data['date'] = dateresponse_data['colname'] = colnameresponse_data['actual'] = actualresponse_data['scope'] = scoperesponse_data['if_except'] = if_exceptreturn json.dumps(response_data, default=str)   except BaseException:logging.critical("Function: getMsg stop ...")cursor.close()db.close()return json.dumps(response_data) @app.route('/getAlarmMsg', methods=['GET'])
def getAlarmMsg():try:evn = request.args['evn']col_name = request.args['col_name']return getMsg(evn, col_name)except BaseException:response_data = {'code': 0, 'msg': 'error'}return json.dumps(response_data) if __name__ == '__main__':   try:                                                           app.run(host='0.0.0.0', port=8090, debug=True)except BaseException:logging.critical("app stop ...")

mysql

mysql里面的表单存储结构为:

mysql> use alarm_msg;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> show tables;
+---------------------+
| Tables_in_alarm_msg |
+---------------------+
| cvm_flow_down       |
| cvm_flow_up         |
| cvm_room_nums       |
| cvm_user_nums       |
| tke_flow_down       |
| tke_flow_up         |
| tke_room_nums       |
| tke_user_nums       |
+---------------------+
8 rows in set (0.00 sec)mysql> select * from cvm_flow_down;
+-----+---------------------+----------+-----------+------------+------------+-------------+-----------+
| id  | order_date          | today_id | col_name  | actual     | scope_left | scope_right | if_except |
+-----+---------------------+----------+-----------+------------+------------+-------------+-----------+
|   1 | 2022-03-14 18:20:43 |      110 | flow_down |  392615039 |    -628001 |   336556517 |         1 |
|   2 | 2022-03-14 18:30:42 |      111 | flow_down |  409642229 |     746497 |   383903533 |         1 |
|   3 | 2022-03-14 18:40:41 |      112 | flow_down |  526891185 |    4350006 |   419925905 |         1 |
|   4 | 2022-03-14 18:50:39 |      113 | flow_down |  557464437 |   10199705 |   451904363 |         1 |
|   5 | 2022-03-14 19:00:48 |      114 | flow_down |  648641400 |   22094813 |   481082273 |         1 |
|   6 | 2022-03-14 19:10:45 |      115 | flow_down |  884153264 |   36335606 |   502285379 |         1 |

最后结果:
在这里插入图片描述

参考

https://v3.bootcss.com/getting-started/
https://bootstrap-table.com/docs/getting-started/download/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/376632.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php编码规则(一)

---恢复内容开始--- <转载自己整理> GNU C 库&#xff08;GNU C Library&#xff0c;又称为glibc&#xff09;是一种按照LGPL许可协议发布的&#xff0c;公开源代码的&#xff0c;免费的&#xff0c;方便从网络下载的C的编译程序。 GNU C运行期库&#xff0c;是一种C函数…

重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传文件...

重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传文件 原文:重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传文件[源码下载] 重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传…

【经验贴】smartCarers在比赛后如何获取更好的发展

博主联系方式: QQ:1540984562 QQ交流群:892023501 群里会有往届的smarters和电赛选手,群里也会不时分享一些有用的资料,有问题可以在群里多问问。 由于最近专栏开了付费,群友让更新一些经验贴,于是有了这篇文章。 一般来说,比赛完了之后是大二结束的暑假,此时有这么几条…

isset()和empty()到底区别是什么。

一招鲜吃遍天&#xff0c;自从看了燕十八关于PHP变量内部机制的那课&#xff0c;解释了一些很久的疑惑&#xff0c;知其然还知其所以然&#xff0c;果然是学习的最佳途径&#xff0c;比背下来要重要N倍。 我们知道一个变量有变量表的位置&#xff0c;然后他指向自己的内存地址&…

html清除图片缓存

img.src ?t(new Date()); 如&#xff1a; <img id "5" src"../../../pics/prod_146/__INLINE__user_nums_cmp_146.png?t"(new Date()) width"1024">

分享下自己编译 XBMC 的过程(zhuan)

刷YunOS赢魅族MX3首先要感谢下网上其他网友的经验&#xff0c;没有这些经验有的问题还是不太好解决&#xff5e; 先介绍下编译环境&#xff0c;操作系统是 CentOS 6.5 64位 (最小桌面版本安装&#xff0c;除了最基本的组件外&#xff0c;类似 java 什么的都没有安装)&#xff0…

使用Xcode和Instruments调试解决iOS内存泄露

虽然iOS 5.0版本之后加入了ARC机制&#xff0c;但由于相互引用关系比较复杂时&#xff0c;内存泄露还是可能存在。所以了解原理很重要。 这里讲述在没有ARC的情况下&#xff0c;如何使用Instruments来查找程序中的内存泄露&#xff0c;以及NSZombieEnabled设置的使用。 本文假设…

0755、0644、0600 linux文件权限

0755->即用户具有读/写/执行权限&#xff0c;组用户和其它用户具有读写权限&#xff1b; 0644->即用户具有读写权限&#xff0c;组用户和其它用户具有只读权限&#xff1b; 0600->仅拥有者具有文件的读取和写入权限

[Android] (在ScrollView里嵌套view)重叠view里面的onTouchEvent的调用方法

在我前面的自定义裁剪窗口的代码中&#xff0c;我把裁剪的view放在了大的scrollview里&#xff0c;这样就出现了程序只能触发scrollview&#xff0c;无法操作我的裁剪窗口。所以我加了那篇博客下面最后两段代码。其实我遇到这个问题的时候是在一个scrollview里添加了一个Editte…

带点击事件的Spinner

最近有一个蛋疼的需求&#xff0c;在下拉框中&#xff0c;如果只有一个值&#xff0c;默认显示出来&#xff0c;有两个或者没有显示请选择&#xff0c;没有点击不弹框&#xff0c;但是要清空&#xff0c;两个点击开要移掉请选择字样的项 本来以为很简单&#xff0c;后来发现没有…

linux进程间通信快速入门【二】:共享内存编程(mmap、XSI、POSIX)

文章目录mmap内存共享映射XSI共享内存POSIX共享内存参考使用文件或管道进行进程间通信会有很多局限性&#xff0c;比如效率问题以及数据处理使用文件描述符而不如内存地址访问方便&#xff0c;于是多个进程以共享内存的方式进行通信就成了很自然要实现的IPC方案。LInux给我们提…

ROBOTS.TXT屏蔽笔记、代码、示例大全

自己网站的ROBOTS.TXT屏蔽的记录&#xff0c;以及一些代码和示例&#xff1a; 屏蔽后台目录&#xff0c;为了安全&#xff0c;做双层管理后台目录/a/xxxx/&#xff0c;蜘蛛屏蔽/a/&#xff0c;既不透露后台路径&#xff0c;也屏蔽蜘蛛爬后台目录 缓存&#xff0c;阻止蜘蛛爬静态…

五大主流浏览器 HTML5 和 CSS3 兼容性比较

转眼又已过去了一年&#xff0c;在这一年里&#xff0c;Firefox 和 Chrome 在拼升级&#xff0c;版本号不断飙升&#xff1b;IE10 随着 Windows 8 在去年10月底正式发布&#xff0c;在 JavaScript 性能和对 HTML5 和 CSS3 的支持方面让人眼前一亮。这篇文章给大家带来《五大主流…

Ubuntu下将Sublime Text设置为默认编辑器

转自将Sublime Text 2设置为默认编辑器 修改defaults.list 编辑/etc/gnome/default.list文件&#xff0c;将其中的所有gedit.desktop替换为sublime_text.desktop。 sublime_text.desktop在/opt/sublime_text目录下&#xff0c;使用ls -al *sublime*命令查看具体文件名。 转载于…

python获取最近N天工作日列表、节假日列表

# 获取最近两周工作日列表、节假日列表 import datetime import chinese_calendar import time import pandas as pd# 将时间戳转换成格式化日期 def timestamp_to_str(timestampNone, format%Y-%m-%d %H:%M:%S):if timestamp:time_tuple time.localtime(timestamp) # 把时间…

保存页面的浏览记录

我的设计思想是将用户的浏览记录保存到cookie里面&#xff0c;然后根据情况处理。cookie里面的数据格式是json格式&#xff0c;方便根据自己的需要添加或者修改属性。引用了3个js文件,下载地址如下。 https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js …

开窍小老虎,一步一个脚印之 初识汇编(一)

最近一直浸淫在计算机编程中无法自拔。哲学 认识论中讲过。人类的求知的过程是由两次飞跃。第一是从感性认识到理性认识&#xff1b;第二是从理性认识到实践。这段话对有些人是适用的。我就是其中的一名。在知乎上求助问题“学计算机要懂汇编吗&#xff1f;”&#xff0c;地下有…

python脚本 请求数量达到上限,http请求重试

由于在内网发送http请求同一个token会限制次数&#xff0c;所以很容易达到网关流量上限。 业务中使用了多线程并发&#xff0c;一个线程发起一次http请求&#xff0c;得到正确结果后返回。这里采用的策略是&#xff0c;如果解析出来达到流量上限&#xff0c;那么该线程休眠一段…

shell 字符串操作

string"abcABC123ABCabc" 字符串长度: echo ${#string} #15 echo expr length $string #15 索引 用法&#xff1a;expr index $string $substring expr index $string "ABC" #4 提取子串 用法&#xff1a;${string:position} echo ${string:3} #A…

Linux 之目录 -鸟哥的Linux私房菜

因为利用 Linux 来开发产品或 distributions 的社群/公司与个人实在太多了, 如果每个人都用自己的想 法来配置档案放置的目录,那么将可能造成很多管理上的困扰。 你能想象,你进入一个企业之后,所 接触到的 Linux 目录配置方法竟然跟你以前学的完全不同吗? 很难想象吧~所以,后来…