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实现的自定义多线程多进程类。分享给大家供大家参考,具体如下: 最近经常使用到对大量文件进行操作的程序以前每次写的时候都要在函数中再写一个多线程多进程的函数,做了...

对Python w和w+权限的区别详解

今日上课,有位同学问到:w和w+有何区别呢。 说实话,我们经常只是用一种权限,没用在意之间的区别,实际上,w+具有可读可写权限,而w只有可写权限。 下面上代码: fd=open(...

跟老齐学Python之深入变量和引用对象

跟老齐学Python之深入变量和引用对象

在《永远强大的函数》那一讲中,老齐我已经向看官们简述了一下变量,之后我们就一直在使用变量,每次使用变量,都要有一个操作,就是赋值。本讲再次提及这个两个事情,就是要让看官对变量和赋值有一个...

简单了解python数组的基本操作

这篇文章主要介绍了简单了解python数组的基本操作,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 一,创建列表 创建一个列表,只要把...

python elasticsearch环境搭建详解

windows下载zip linux下载tar 下载地址:https://www.elastic.co/downloads/elasticsearch 解压后运行:bin/elast...