• 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
  • 相关阅读:
    JAVA企业级开发-BOM&DOM(03)
    JAVA企业级开发-JavaScript(02)
    JAVA基础--IO输入输出(File使用)17
    day03-CSS(1)
    day02-HTML(2)
    day01-HTML(1)
    apache2.4 只允许合法域名访问网站 禁止使用ip、非法域名访问
    电子书格式转换
    推荐几本学习MySQL的好书
    Linux上vi(vim)编辑器使用教程
  • 原文地址:https://www.cnblogs.com/forilen/p/4229432.html
Copyright © 2020-2023  润新知