1. 程式人生 > >django 將一維陣列交給前臺頁面

django 將一維陣列交給前臺頁面

def testjquery(req):
 print req.get_full_path()
 print req.GET['username'];
 print req.GET['content'];
 d=[]
 d.append(req.GET['username'])
 d.append(req.GET['content'])
 print type(d)
 print d
 return HttpResponse( req.GET['username'] + req.GET['content'])
 
 return render(req,'cmdb/modifyBtn.html',{'info':info})
 
 def testjquery(req):
 print req.get_full_path()
 print req.GET['username'];
 print req.GET['content'];
 d=[]
 d.append(req.GET['username'])
 d.append(req.GET['content'])
 print type(d)
 print d
 return render(req,'testjquery.html',{'info':d})
 
 [22/Jan/2018 12:52:54] "GET /testjquery/?username=123&content=789 HTTP/1.1" 200 614
/testjquery/?username=123&content=789
123
789
<type 'list'>
[u'123', u'789']
[22/Jan/2018 12:52:55] "GET /testjquery/?username=123&content=789 HTTP/1.1" 200 614

 
 將陣列分配給前臺頁面
 
 {% 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}}>  
  
  node2:/django/mysite/news/templates#cat testjquery.html 
            <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}}>  
                <input type="submit" value="裝置修改" class="equipment_add_btn">  
                                {% endfor %}  
            </form>