1. 程式人生 > >html遍歷陣列來填充表格

html遍歷陣列來填充表格

1.
[[email protected] templates]# cat addmqmonitor.html 
<html>
<head>
	<title>運維平臺</title>
	<link rel="stylesheet" type="text/css" href="/static/Css/Monitor/addmqmonitor.css">
	<link rel="stylesheet" type="text/css" href="/static/Css/Public/header.css">
	<link rel="stylesheet" type="text/css" href="/static/Css/Public/menu.css">
</head>
<body>
	<include file="Public:header"/>
	<div class="content">
		<include file="Public:menu"/>
		<div class="con fl">
			<form id="condition" action="/addmqmonitor/" method="post">
				
				<label class="condition">應用</label><input type="text" name="app" class="equipment_sz">
				<label class="condition">佇列管理器</label><input type="text" name="qmgr" class="equipment_sz">
				<label class="condition">通道名稱</label><input type="text" name="channel" class="equipment_sz">
                                <br />
				<label class="condition">IPADDR</label><input type="text" name="ipaddr" class="equipment_sz">
				<label class="condition">PORT</label><input type="text" name="port" class="equipment_sz">
				<label class="condition">佇列監控閾值</label><input type="text" name="depth" class="equipment_sz">
				<label class="condition">是否監控</label><input type="text" name="flag" class="equipment_sz">
                                <br />
				<input type="submit" value="裝置新增" class="equipment_add_btn">
			</form>
		</div>
	</div>
</body>
<script type="text/javascript" src="/static/Js/jquery-2.2.2.min.js"></script>
<!-- <script type="text/javascript" src="/static/Js/Equipment/addEquipment.js"></script> -->
</html>


2. 直接呼叫addmqmonitor方法

def addmqmonitor(req):
   print req.get_full_path()
   app= req.POST['app']
   qmgr= req.POST['qmgr']
   channel= req.POST['channel']
   ipaddr= req.POST['ipaddr']
   port= req.POST['port']
   depth= req.POST['depth']
   flag= req.POST['flag']
   conn= MySQLdb.connect(
        host='127.0.0.1',
        port = 3306,
        user='root',
        passwd='1234567',
        db ='DEVOPS'
        )
   cursor = conn.cursor()
   sql = "insert into mon_mq(name,qmgr,channel,ipaddr,port,depth,flag) values('%s','%s','%s','%s','%s','%s','%s')" % (app,qmgr,channel,ipaddr,port,depth,flag)
   cursor.execute(sql)
   conn.commit()
   a = cur.execute("select name,qmgr,channel,ipaddr,port,flag from  mon_mq" )
   info = cur.fetchall()
   print info
   print type(info)
   return render(req,'listmqinfo.html',{'info':info})

   
  新增成功後跳轉到顯示頁面
  
  
  返回東西內容:
  Django version 1.11, using settings 'mysite.settings'
Starting development server at http://0.0.0.0:9000/
Quit the server with CONTROL-C.
/addmqmonitor/
((u'\u7535\u7968\u7cfb\u7edf', u'QMEMBFE', u'SYSTEM.ADMIN.SVRCONN', u'10.3.244.1', u'1417', u'1'), 
(u'\u5927\u5c0f\u989d\u8d85\u7ea7\u7f51\u94f6\u524d\u7f6e\u4e3b\u673a', u'QMUMBFEA', u'SYSTEM.DEF.SVRCONN', u'10.2.239.2', u'1424', u'1'),
 (u'\u5927\u5c0f\u989d\u8d85\u7ea7\u7f51\u94f6\u524d\u7f6e\u5907\u673a', u'QMUMBFEA', u'SYSTEM.DEF.SVRCONN', u'10.2.239.1', u'1424', u'1'), 
 (u'\u4e0a\u6d77\u540c\u57ce\u524d\u7f6e\u673a', u'DSFSHTLCB', u'SYSTEM.DEF.SVRCONN', u'10.3.221.1', u'1415', u'1'),
 (u'\u4e0a\u6d77\u540c\u57ce\u524d\u7f6e\u673a', u'SMPSHTLCB', u'SYSTEM.DEF.SVRCONN', u'10.3.221.1', u'1414', u'1'),
 (u'\u8d22\u653f\u975e\u7a0e', u'FS_TLYH_SEND', u'SYSTEM.ADMIN.SVRCONN', u'10.3.217.1', u'1419', u'1'),
 (u'\u56fd\u9645\u7ed3\u7b97', u'QM_CODE0123', u'CHL.SC.BANK0123', u'10.3.248.1', u'1419', u'1'), 
 (u'\u56fd\u9645\u7ed3\u7b97', u'QM_RCPMIS_613057100058_01', u'SVRCONN', u'10.3.248.1', u'9100', u'1'), 
 (u'TIPS\u7cfb\u7edf', u'QM_TIPS_613057100058_01', u'SYSTEM.ADMIN.SVRCONN', u'10.3.233.1', u'9009', u'1'),
 (u'\u8d22\u653f\u975e\u7a0e', u'LQQCZJ_SEND', u'SYSTEM.ADMIN.SVRCONN', u'10.3.217.1', u'4515', u'0'),
 (u'\u8d22\u653f\u975e\u7a0e', u'LQQCZJ_RECV', u'SYSTEM.ADMIN.SVRCONN', u'10.3.217.1', u'4514', u'1'), 
 (u'\u8d22\u653f\u975e\u7a0e', u'LQQCZJ_PLSEND', u'SYSTEM.ADMIN.SVRCONN', u'10.3.217.1', u'4517', u'1'),
 (u'\u8d22\u653f\u975e\u7a0e', u'LQQCZJ_PLRECV', u'SYSTEM.ADMIN.SVRCONN', u'10.3.217.1', u'4516', u'1'), 
 (u'\u8d22\u653f\u975e\u7a0e', u'LQQCZJ_GWKSEND', u'SYSTEM.ADMIN.SVRCONN', u'10.3.217.1', u'4522', u'1'), 
 (u'\u8d22\u653f\u975e\u7a0e', u'LQQCZJ_GWKRECV', u'SYSTEM.ADMIN.SVRCONN', u'10.3.217.1', u'4521', u'1'),
 (u'\u8054\u7f51\u6838\u67e5', u'QM_PICP_313345010019_01', u'SVRCONN', u'10.3.240.1', u'9010', u'1'), (u'aaa', u'bbb', u'cccc', u'ddd', u'eee', u'0'))
<type 'tuple'>




返回的多維陣列交給listmqinfo.html頁面
3.
[
[email protected]
templates]# cat listmqinfo.html <html> <head> <title>運維平臺</title> <link rel="stylesheet" type="text/css" href="/static/Css/Equipment/modifyBtn.css"> <link rel="stylesheet" type="text/css" href="/static/Css/Public/header.css"> <link rel="stylesheet" type="text/css" href="/static/Css/Public/menu.css"> </head> <table border="10"> {% for x in info %} <tr> <th>{{x.0}}</th> <th>{{x.1}}</th> <td>{{x.2}}</td> <td>{{x.3}}</td> <td>{{x.4}}</td> <td>{{x.5}}</td> </tr> {% endfor %} </table> 表格遍歷多維陣列