今天开始学习使用Python写一下服务端,经过研究,发现bottle框架轻量、简单、易用,非常适合我这种小白学习。
安装bottle框架非常简单,它不需要额外的库,只要把一个文件下载并放到开发目录后就OK了。
from bottle import route, run, template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
run(host='localhost', port=8080)
代码就这么几行,然后访问http://localhost:8080/hello/world,就可以获得Hello word!
改变不同的路径,比如/hello/there,就变成Hello there!