樹莓派4B上 tornado的安裝 以及訪問傳參

安裝tornado:
 

wget https://pypi.python.org/packages/source/t/tornado/tornado-4.3.tar.gz

tar xvzf tornado-4.3.tar.gz

cd tornado-4.3

python setup.py build

sudo python setup.py install



py代碼:

#coding: utf8 

import sys

import tornado.ioloop

import tornado.web

import tornado.httpserver

import tornado.options

from tornado.options import define,options



class IndexHandler(tornado.web.RequestHandler):

        def get(self):

                self.render("index.html") #請在py腳本同一目錄放置此頁面

        def post(self): 

                arg = self.get_argument('canshu')                

                self.write("你訪問的參數爲::"+arg)

                

if __name__ == '__main__':

    tornado.options.parse_command_line()

    app = tornado.web.Application(handlers=[(r"/",IndexHandler)])

    http_server = tornado.httpserver.HTTPServer(app)

    http_server.listen(8000)

    tornado.ioloop.IOLoop.instance().start()



 將py代碼同一目錄下放置index.html:

<!DOCTYPE html>
<html lang='zh-CN'>
<head>

<title>智能家居</title>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
<link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
<script src="https://www.layuicdn.com/layui/layui.js"></script>
<body  id='explores-show'>
<blockquote class="layui-elem-quote layui-text">
表頭說明
</blockquote>

              
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>表單集合演示</legend>
</fieldset>

<form class="layui-form" action="">
  <div class="layui-form-item">
    <label class="layui-form-label"  data-anim="layui-anim-upbit">開關-默認開</label>
    <div class="layui-input-block">
      <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
    </div>
  </div>
</form>

<script src="//res.layui.com/layui/dist/layui.js" charset="utf-8"></script>
<script>
layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
   //監聽指定開關
  form.on('switch(switchTest)', function(data){
    layer.msg('開關checked:'+ (this.checked ? 'true' : 'false'), {
      offset: '6px'
    });
    if(this.checked){
        $.ajax({url:"http://192.168.1.105:8000/?canshu=1",async:false});
        }else{
        $.ajax({url:"http://192.168.1.105:8000/?canshu=2",async:false});
            }    
  });
});
</script>
</html>

訪問:

http://你的樹莓派IP:8000/?canshu=2

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章