如何将龙卷风中的参数传递给html文件?

时间:2017-11-27 12:01:53

标签: python html jsp web tornado

我已经共享了我的代码的一部分,在类'Room'中,变量'nw'具有查询字符串值。现在,我希望html文件动态地使用查询字符串值自动填充'nw'字段。我如何得到它?self.get_namespaces有帮助吗?

    class Room(tornado.web.RequestHandler):
    def get(self):
       nw=self.get_argument("nw")
       print(nw)
       self.render("RoomPost.html")  

class static(tornado.web.RequestHandler):
    def get(self,key):
           iname="static/" +key
    print iname
              self.render(iname)        
settings = {
    'debug': True,
    'static_path': 'static'}

application = tornado.web.Application([

        (r"/room",Room ),

        #(r"/static/(.*)",static)
        ], **settings)
if __name__ == "__main__":
    application.listen(5500)
tornado.ioloop.IOLoop.instance().start()

以下是html文件

<html>
<head>
<link rel="stylesheet" href="{{ static_url("css/registration.css")}} />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

</head>
<body>
<c:import url="InnerHeader.js"></c:import>
<br><br><br>

<center>
    <form action="/room" method="post" >
    <fieldset>
        <legend>
            <b1>Room Add</b1>
        </legend>
        <table class="registerTable">
            <tr>
                <td>Name of NW/Name of Home</td>
                <td><input type="text" name="nw" placeholder="Kfx-Home"
                    maxlength="15" size="30" autofocus required/></td>
            </tr>

                <tr>
                <td colspan="2" align="center" > &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
                <input type="submit"     value="  Submit  " /></td>
                </tr>

        </table>
        </fieldset>
    </form>
</center>

1 个答案:

答案 0 :(得分:0)

以下链接帮助我找到答案:

How to pass arguments from tornado to a js file but not html?

我在tornado脚本中添加了self.render(“RoomPost.jsp”,nw = nw)并且自动对焦需要value =“{{nw}}”readonly /&gt;在.jsp脚本中。