python微框架Bottle(http)
2015-07-06 20:51
253 查看
环境:
win7系统
Python2.7
因为之前的游戏中已经有了一套完整的激活码生成工具和验证http服务器,所以直接拿过来使用了。
都是用Python写的,http服务器用到了Python微框架Bottle。
Bottle是一个非常精致的WSGI框架,它提供了 Python Web开发中需要的基本支持:
URL路由,
Request/Response对象封装,
模板支持,
与WSGI服务器集成支持。
只有一个bottle.py文件,没有任何标准库之外的依赖。
还可以用如下格式返回静态文件:
参考:
http://bottlepy.org/docs/dev/tutorial.html
win7系统
Python2.7
一 背景和概述
目前项目中需要添加一个激活码功能,打算单独弄一个http服务器来写。因为之前的游戏中已经有了一套完整的激活码生成工具和验证http服务器,所以直接拿过来使用了。
都是用Python写的,http服务器用到了Python微框架Bottle。
Bottle是一个非常精致的WSGI框架,它提供了 Python Web开发中需要的基本支持:
URL路由,
Request/Response对象封装,
模板支持,
与WSGI服务器集成支持。
二 下载
地址:http://bottlepy.org/docs/dev/index.html只有一个bottle.py文件,没有任何标准库之外的依赖。
三 测试
新建文件useBottle.py,内容如下:from bottle import route, run @route('/hello') #将路由/hello关联到函数hello() def hello(): return "Hello World!" run(host='localhost', port=8080, debug=True)
四 运行结果
五 稍微复杂一点的例子
from bottle import Bottle, route, run, template, error app = Bottle() @app.route('/hello') def hello(): return "Hello World!" @app.route('/') # 缺省路由 @app.route('/hello/<name>') # hello下的所有路由 def greet(name='Stranger'): return template('Hello {{name}}, how are you?', name=name) @app.error(404) def error404(error): return 'Nothing here, sorry' run(app, host='localhost', port=8080)
还可以用如下格式返回静态文件:
@route('/static/<filepath:path>') def server_static(filepath): return static_file(filepath, root='/path/to/your/static/files')
参考:
http://bottlepy.org/docs/dev/tutorial.html
相关文章推荐
- BP神经网络
- Cocos2d-x-3.6学习(三)---- TestCpp学习
- Linux下TCP/IP网络编程
- linux网络设备驱动DM9000驱动分析(4)
- 简单区分VMware的三种网络连接模式(bridged、NAT、host-only)
- 【网络流】 HDOJ 4307 Matrix
- luasocket系列: luasocket tcp
- linux网络设备驱动DM9000驱动分析(3)
- linux网络设备驱动DM9000驱动分析(2)
- 黑马程序员—网络编程
- JAVA实现反向连接_____屏幕监视 (TCP)
- 图解HTTPS
- tcp socket and i/o
- ubuntu sever 网络代理设置
- MATLAB的人工神经网络应用
- atc工具使用-国内运营商的网络环境
- android 获取手机网络信息相关内容
- 教你识別和区分网络及使用者
- 简述网络通信安全技术及openssl命令行工具的基本使用
- zabbix监控tcp连接数