【脚本语言系列】关于PythonWeb服务器Bottle,你需要知道的事
来源:互联网 发布:directx9安装需要网络 编辑:程序博客网 时间:2024/05/29 12:02
如何使用bottle
欢迎页面
# -*- coding:utf-8 -*-from bottle import route, run@route("/")def home(): return "Hello AllenMoore!"run(host="localhost", port=9999, debug=True)
Bottle v0.12.13 server starting up (using WSGIRefServer())...Listening on http://localhost:9999/Hit Ctrl-C to quit.127.0.0.1 - - [22/Jun/2017 10:26:00] "GET / HTTP/1.1" 200 17127.0.0.1 - - [22/Jun/2017 10:44:10] "GET / HTTP/1.1" 200 17
静态网页
# -*- coding:utf-8 -*-from bottle import route, run, static_file@route("/")def main(): return static_file("temp.html", root=".")run(host="localhost", port=9999)
Bottle v0.12.13 server starting up (using WSGIRefServer())...Listening on http://localhost:9999/Hit Ctrl-C to quit.127.0.0.1 - - [22/Jun/2017 10:46:17] "GET / HTTP/1.1" 200 62
动态网页
# -*- coding:utf-8 -*-from bottle import route, run, static_file@route("/")def main(): return static_file("temp.html", root=".")@route("/echo/<pagename>")def echo(pagename): return "Hello %s!" %pagenamerun(host="localhost", port=9999)
Bottle v0.12.13 server starting up (using WSGIRefServer())...Listening on http://localhost:9999/Hit Ctrl-C to quit.127.0.0.1 - - [22/Jun/2017 10:47:27] "GET /favicon.ico HTTP/1.1" 404 742127.0.0.1 - - [22/Jun/2017 10:47:28] "GET / HTTP/1.1" 304 0127.0.0.1 - - [22/Jun/2017 10:47:49] "GET /echo/AllenMoore HTTP/1.1" 200 17
测试效果
# -*- coding:utf-8 -*-import requestsresp = requests.get("http://localhost:9999/echo/AllenMoore")if resp.status_code == 200 and resp.text == "Hello AllenMoore!": print "Got Good News!"else: print "Got Bad News: %s" %resp.text
Got Good News!
什么是bottle
Bottle是简单的Web服务器。
为何使用bottle
Bottle有且只有一个简单的Python文件,非常易于使用和部署。
阅读全文
0 0
- 【脚本语言系列】关于PythonWeb服务器Bottle,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器Flask,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器apache+mod_wsgi,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务器Nginx+uWSGI,你需要知道的事
- 【脚本语言系列】关于PythonWeb客户端-服务器模块http-urllib,你需要知道的事情
- 【脚本语言系列】关于PythonWeb访问urllib,你需要知道的事
- 【脚本语言系列】关于PythonWeb访问ftplib,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化BeautifulSoup,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化webbrowser模块,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化REST,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化Web API,你需要知道的事
- 【脚本语言系列】关于PythonWeb客户端标准库requests,你需要知道的事情
- 【脚本语言系列】关于Python系统管理,你需要知道的事
- 【脚本语言系列】关于Python容器,你需要知道的事
- 【脚本语言系列】关于Python调试报错,你需要知道的事
- 【脚本语言系列】关于Python开发环境搭建,你需要知道的事
- 【脚本语言系列】关于Python数值计算NumPy, 你需要知道的事
- 【脚本语言系列】关于Python测试工具lettuce, 你需要知道的事
- 离散题目10
- HBase开发中RpcRetryingCaller Call exception问题
- Android Picasso实现圆形图片和圆角图片
- codeforces 812b Sagheer, the Hausmeister
- Linux系统内存管理
- 【脚本语言系列】关于PythonWeb服务器Bottle,你需要知道的事
- grep、sed、awk命令使用参数说明
- CSS3线性渐变与径向渐变
- BZOJ 2428 [HAOI2006]均分数据 模拟退火
- bash脚本基础(二)
- Flask成长笔记--依赖包操作
- Leetcode 332 Reconstruct Itinerary
- vlc for android 完全编译
- dup/dup2/dup3(输入文件描述符重定向)