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基础之入门必看操作

python基础之入门必看操作

这里提供在使用python进行开发中常使用到的方法技巧,如有不对欢迎批评指正。 要点:开发中类、变量特性查询,类型就是类,断言的使用,深浅复制判断等 python脚本文件是使用UTF-8...

Python实现的旋转数组功能算法示例

本文实例讲述了Python实现的旋转数组功能算法。分享给大家供大家参考,具体如下: 一、题目 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。 例1: 输入: [...

Python切片操作实例分析

本文实例讲述了Python切片操作。分享给大家供大家参考,具体如下: 在很多编程语言中,针对字符串提供了截取函数,其实目的就是对字符串切片。Python没有针对字符串的截取函数,只需要切...

python-Web-flask-视图内容和模板知识点西宁街

基本使用 #设置cookie值 @app.route('/set_cookie') def set_cookie(): response = make_response("...

Python实现压缩文件夹与解压缩zip文件的方法

本文实例讲述了Python实现压缩文件夹与解压缩zip文件的方法。分享给大家供大家参考,具体如下: 直接上代码 #coding=utf-8 #甄码农python代码 #使用zipfi...