先使用pip install bottle安装bottle,之后编辑文本:
from bottle import route,run,template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!',name=name)
run(host='localhost',port=80)
保存为py文件后,使用python 命令运行该文件即可。
这篇博客介绍了如何利用Python的Bottle微型Web框架搭建一个简单的HTTP服务器。首先通过pip安装Bottle库,然后编写Python代码定义路由,如'/hello/<name>',返回一个带有用户传入姓名的HTML响应。最后,指定服务器运行在本地主机的80端口并启动。运行此Python脚本,即可在浏览器中访问创建的服务器。
先使用pip install bottle安装bottle,之后编辑文本:
from bottle import route,run,template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!',name=name)
run(host='localhost',port=80)
保存为py文件后,使用python 命令运行该文件即可。

被折叠的 条评论
为什么被折叠?