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

yipeiwu_com6年前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子线程退出及线程退出控制的代码

下面通过代码给大家介绍python子线程退出问题,具体内容如下所示: def thread_func(): while True: #do something...

在python中用print()输出多个格式化参数的方法

不废话,直接贴代码: disroot = math.sqrt(deta) root1 = (-b + disroot)/(2*a) root2 = (-b - disroot)/(2...

深入解析python中的实例方法、类方法和静态方法

深入解析python中的实例方法、类方法和静态方法

1、实例方法/对象方法 实例方法或者叫对象方法,指的是我们在类中定义的普通方法。 只有实例化对象之后才可以使用的方法,该方法的第一个形参接收的一定是对象本身 2、静态方法 (1).格式...

使用Python实现将list中的每一项的首字母大写

如下所示: L = ['adam', 'Lisa', 'bart', 'Paul'] m=0 for i in L: L[m]=i[0].upper()+i[1:] m=m+...

Python+OpenCv制作证件图片生成器的操作方法

本项目使用Python和OpenCv实现身份证图片生成工具,填入信息,选择一张头像图片(即可生成黑白和彩色身份证图片)。可以选择是否自动抠图,自动抠图目前仅支持蓝色背景,对自动抠图效果不...