Django開發之html互動

來源:互聯網
上載者:User

標籤:

html中使用者輸入資訊,由Django的view.py處理,大致用到了以下幾類格式:

1. 文字框

<input type="text" name="vid" size="10" height="20">或由bootcss修飾的<div class="col-sm-2" ><input type="text" class="form-control" id="username" name="username" placeholder="Username"></div>

  

這種相對比較簡單

version_num=request.GET.get("vid")

  

2. 文字框

<td width="30%" align="center" valign="top">粘帖需要發布的其他所有UI</td><td><textarea rows="10" cols="40" id="newui" name="newui" ></textarea></td>

 這種要這樣接收,返回結果是一個列表,相對比較好處理

    otherNewUI=request.GET.get("newui").encode(‘utf8‘).split("\r\n")    ‘‘‘return result like this:     [u‘GameStub.swf.new‘, u‘giftui.swf‘, u‘zhuui2.swf‘]    ‘‘‘

  

3. 多選按鈕,傳回值也是一個列表

        <td width="30%" align="center" valign="top" >選擇ini.xml中需要發布的ui</td>        <td>            <input type="checkbox" name="ui_list" value="GameStub.swf.new" />GameStub.swf.new<br />            <input type="checkbox" name="ui_list" value="giftui.swf" />giftui.swf<br />            <input type="checkbox" name="ui_list" value="zhuui2.swf" />zhuui2.swf<br />            <input type="checkbox" name="ui_list" value="vipui.swf" />vipui.swf<br />            <input type="checkbox" name="ui_list" value="giftboxui.swf" />giftboxui.swf<br />            <input type="checkbox" name="ui_list" value="baseui.swf" />baseui.swf<br />            <input type="checkbox" name="ui_list" value="xinshouui.swf" />xinshouui.swf<br />            <input type="checkbox" name="ui_list" value="buildingui.swf" />buildingui.swf<br />            <input type="checkbox" name="ui_list" value="jiuguanui.swf" />jiuguanui.swf<br />        </td>
    newUiList=request.GET.getlist("ui_list")    ‘‘‘return result like this:     [u‘GameStub.swf.new‘, u‘giftui.swf‘, u‘zhuui2.swf‘]    ‘‘‘

  

4. cookie用法

寫cookie,並執行跳轉    response=render_to_response(‘verIntegration/uiPrepare.html‘,{"current_version":current_version,"gameName":gameName})    response.set_cookie("game",game,600)    return response讀cookie,判斷cookie是否失效    if "game" in request.COOKIES:        game=request.COOKIES["game"]        gameName=CONFIG[game][‘name‘]        print "cookie still in "    else:        gameName="未知"        print "cookie has gone"        return render_to_response(‘verIntegration/uiPrepare.html‘,{"gameName":gameName})

  

5. pexpect方法執行互動式操作

def pullFile(gameConfig,remoteFileName,localFileName):    #使用目錄均為相對路徑,絕對路徑從字典中讀取    cmd="scp -P %s %[email protected]%s:%s/%s %s/%s" % (gameConfig[‘port‘],gameConfig[‘user‘],gameConfig[‘ip‘],gameConfig[‘remote_dir‘],remoteFileName,gameConfig[‘local_dir‘],localFileName)    expect1="password: "    child = pexpect.spawn(cmd)    child.expect(expect1)    child.sendline(gameConfig[‘password‘])    child.read()    return None

  

6. pexpect遠程執行指令碼,這個可以參考pexpect的example中的hive.py

def remoteRun(gameConfig,cmd):    srv_ip=gameConfig[‘ip‘]    srv_port=gameConfig[‘port‘]    srv_username=gameConfig[‘user‘]    srv_password=gameConfig[‘password‘]    try:        ssh=paramiko.SSHClient()        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())        ssh.connect(srv_ip,srv_port,srv_username,srv_password,timeout=5)        stdin, stdout, stderr = ssh.exec_command(cmd)                outlist=[]        for out in stdout:            outlist.append(out.strip(‘\n‘))    except Exception,e:        print "Error"        print e    return None

 

Django開發之html互動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.