Bottle是一个轻量化的,不依靠其他的插件,能够快速的建立一个Web服务器。
话不多说,直入主题。本教程在树莓派的python3中运行调试。
1、安装,打开终端输入:
sudo apt-get install python-bottle
2、编程小例程:hello world
from bottle import route, run //调入需要的函数 @route('/hello') //装饰器指向hello()子函数 def hello(): return "Hello World!" run(host='localhost', port=8080) //run通常放在结束,开始服务器,以ctrl+C结束
运行脚本后,在同一网络下访问http://localhost:8080/hello,就能看到web中显示Hello World!
- 这一节主要的就是route和run。这是核心的两个函数,细细体会。即使小白也可以从头开始学
![cab315d0c618d879c1b4b42a4fe21f0f.png](https://i-blog.csdnimg.cn/blog_migrate/ad204b814bb9ad7198b10ed56307e16f.jpeg)