<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Web开发 :: 标签 :: yafeng 的博客</title>
    <link>https://yafengabc.github.io/tags/web%E5%BC%80%E5%8F%91/index.html</link>
    <description></description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Sat, 19 Sep 2026 16:30:07 +0800</lastBuildDate>
    <atom:link href="https://yafengabc.github.io/tags/web%E5%BC%80%E5%8F%91/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>简单的实现树莓派的WEB控制</title>
      <link>https://yafengabc.github.io/cnblogs/p5197844/index.html</link>
      <pubDate>Thu, 18 Feb 2016 12:55:00 +0800</pubDate>
      <guid>https://yafengabc.github.io/cnblogs/p5197844/index.html</guid>
      <description>最终效果如图：&#xA;用到的知识：Python Bottle HTML Javascript JQuery Bootstrap AJAX 当然还有 linux&#xA;我去，这么多……我还是一点一点说起吧……&#xA;先贴最终的源代码：&#xA;#!/usr/bin/env python3 from bottle import get,post,run,request,template @get(&#34;/&#34;) def index(): return template(&#34;index&#34;) @post(&#34;/cmd&#34;) def cmd(): print(&#34;按下了按钮: &#34;+request.body.read().decode()) return &#34;OK&#34; run(host=&#34;0.0.0.0&#34;) 没错，就10句，我一句一句解释：&#xA;1.#!/usr/bin/env python3 ，告诉shell这个文件是Python源代码，让bash调用python3来解释这段代码&#xA;2.from bottle import get,post,run,request,template ，从bottle框架导入了我用到的方法、对象&#xA;下边几句是定义了2个路由，一个是“/”一个是“/cmd”,前者是get类型（用@get装饰），后者是POST类型（用的@post装饰）&#xA;第一个路由很简单，就是读取index模版（模版就是个html啦）并发送到客户端（浏览器），因为路径是“/”也就是比如树莓派的IP地址是：192.168.0.10&#xA;那用http://192.168.0.10:8080就访问到了我们的&#34;/”路由（bottle默认端口是8080）&#xA;同理，第二个路由的路径是“/cmd”也就是访问http://192.168.0.10:8080/cmd就访问到了第二个路由&#xA;最后一句：run(host=“0.0.0.0”)就是调用bottle的run方法，建立一个http服务器，让我们能通过浏览器访问我们的界面。&#xA;下边我详细的解释一下这些代码的作用：&#xA;第一个路由的作用就是扔给浏览器一个HTML（index.tpl）文档，显示这个界面：&#xA;这个文件的源代码如下：&#xA;&lt;!DOCTYPE html&gt; &lt;html lang=&#34;en&#34;&gt; &lt;head&gt; &lt;meta charset=&#34;UTF-8&#34;&gt; &lt;meta name=&#34;viewport&#34; content=&#34;width=device-width, initial-scale=1.0&#34;&gt; &lt;title&gt;遥控树莓派&lt;/title&gt; &lt;link href=&#34;//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css&#34; rel=&#34;stylesheet&#34; media=&#34;screen&#34;&gt; &lt;script src=&#34;http://code.jquery.com/jquery.js&#34;&gt;&lt;/script&gt; &lt;style type=&#34;text/css&#34;&gt; #up { margin-left: 55px; margin-bottom: 3px; } #down { margin-top: 3px; margin-left: 55px; } &lt;/style&gt; &lt;script&gt; $(function(){ $(&#34;button&#34;).click(function(){ $.post(&#34;/cmd&#34;,this.id,function(data,status){}); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=&#34;container&#34; class=&#34;container&#34;&gt; &lt;div&gt; &lt;button id=&#34;up&#34; class=&#34;btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-up&#34;&gt;&lt;/button&gt; &lt;/div&gt; &lt;div&gt; &lt;button id=&#39;left&#39; class=&#34;btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-left&#34;&gt;&lt;/button&gt; &lt;button id=&#39;stop&#39; class=&#34;btn btn-lg btn-primary glyphicon glyphicon-stop&#34;&gt;&lt;/button&gt; &lt;button id=&#39;right&#39; class=&#34;btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-right&#34;&gt;&lt;/button&gt; &lt;/div&gt; &lt;div&gt; &lt;button id=&#39;down&#39; class=&#34;btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-down&#34;&gt;&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;script src=&#34;//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js&#34;&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; 这个内容有点多，不过很简单，就是引用了jquery bootstrap这两个前端框架，加了5个按钮(之间的代码)。当然我用了bootstrap内置的上下左右停止这几个图标，这5个按钮的id分辨定义成up，down，left，right，stop，然后写了如下的关键代码：</description>
    </item>
  </channel>
</rss>