zoukankan      html  css  js  c++  java
  • Django开发之html交互

    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("
    ")
        '''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 %s@%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('
    '))
        except Exception,e:
            print "Error"
            print e
        return None
  • 相关阅读:
    【XAF】非持久化对象分组和属于不同会话
    【原创】XAF 非持久对象界面中更新xpo的状态查询
    Java字符串操作方法集
    Java易忘知识点统计
    Android常用依赖库搜集
    Android Studio报错Unable to resolve dependency for ':app@release/compileClasspath':无法引用任何外部依赖的解决办法
    Codewars练习Python
    Python学习日记之正则表达式re模块
    Linux学习日记之crontab使用notify-send实现每小时通知提醒
    Linux学习日记之Deepin下查看crontab运行日志
  • 原文地址:https://www.cnblogs.com/forilen/p/4229432.html
Copyright © 2011-2022 走看看