django将数组传递给前台模板的方法

yipeiwu_com5年前Python基础

将数组传递给前台模板:

1.

def modifyBtn(req,modifyip):
  print modifyip
  conn= MySQLdb.connect(
    host='localhost',
    port = 3306,
    user='root',
    passwd='1234567',
    db ='DEVOPS'
    )
  cur = conn.cursor()
  a = cur.execute("select ip,info,env from machine_info where ip=%s ",[modifyip])
  info = cur.fetchall()
  print info
  print type(info)
  return render(req,'cmdb/modifyBtn.html',{'info':info})

2. node2:/django/mysite/news/templates/cmdb#cat modifyBtn.html

<html>
<head>
 <title>运维平台</title>
 <link rel="stylesheet" type="text/css" href="/static/Css/Equipment/modifyBtn.css" rel="external nofollow" >
 <link rel="stylesheet" type="text/css" href="/static/Css/Public/header.css" rel="external nofollow" >
 <link rel="stylesheet" type="text/css" href="/static/Css/Public/menu.css" rel="external nofollow" >
</head>
<body>
 <include file="Public:header"/>
 <div class="content">
 <include file="Public:menu"/>
 <div class="con fl">
  <form id="condition" action="/static/modifyEquipment" method="post">
                {% for x in info %}
  <label class="condition">地址</label><input type="text" name="ip" class="equipment_sz" value={{x.0}}>
  <label class="condition">描述</label><input type="text" name="info" class="equipment_sz" value={{x.1}}>
  <label class="condition">环境</label><input type="text" name="env" class="equipment_sz" value={{x.2}}>
  <input type="submit" value="设备修改" class="equipment_add_btn">
                {% endfor %}
  </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>

以上这篇django将数组传递给前台模板的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

解决Python使用列表副本的问题

要使用一个列表的副本,要用切片进行列表复制,这样会形成两个独立的列表。 切记不要将列表赋值给一个列表,因为这样并不能得到两个列表。 1、使用赋值语法创建列表副本的问题 下边就将列表赋值,...

Python 生成一个从0到n个数字的列表4种方法小结

我就废话不多说了,直接上代码吧! 第一种 def test1(): l = [] for i in range(1000): l = l + [i] 第二种(app...

详解Python可视化神器Yellowbrick使用

详解Python可视化神器Yellowbrick使用

机器学习中非常重要的一环就是数据的可视化分析,从源数据的可视化到结果数据的可视化都离不开可视化工具的使用,sklearn+matplotlib的组合在日常的工作中已经满足了绝对大多数的需...

python3中int(整型)的使用教程

Python3支持三种不同的数值类型: 整型(int)--通常被称为是整型或整数,可以是正整数或负整数,不带小数点。Python3整型是没有限制大小的,可以当做long类型使用,...

基于python中__add__函数的用法

运算符重载 _add ##定义:让自定义的类生成的对象(实例)能够使用运算符进行操作 class Vector01: ‘'‘定义一个一维向量''' def init(self,x...