Python bottle 最小示例
使用 bottle HTTP 服务器的最小 hello world 类示例:
bottle_hello.py
#!/usr/bin/env python3
from bottle import route, run
@route('/')
def index():
return "Hello bottle!"
run(host='localhost', port=9000)运行此文件(并保持运行),然后导航到 http://localhost:9000 查看 Hello bottle! 消息。
如果你看到此错误消息:
bottle_module_error.txt
Traceback (most recent call last):
File "./server.py", line 2, in <module>
from bottle import route, run
ModuleNotFoundError: No module named 'bottle'你需要使用以下命令安装 bottle
install_bottle.sh
pip install -U bottle取决于你使用的 Python 版本和配置。
Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow