环境:

win7系统

Python2.7

一 背景和概述

眼下项目中须要加入一个激活码功能,打算单独弄一个httpserver来写。

由于之前的游戏中已经有了一套完整的激活码生成工具和验证httpserver,所以直接拿过来使用了。

都是用Python写的,httpserver用到了Python微框架Bottle。

Bottle是一个很精致的WSGI框架。它提供了 Python Web开发中须要的基本支持:

URL路由。

Request/Response对象封装,

模板支持,

与WSGIserver集成支持。

二 下载

地址: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

最新文章

  1. linux下ftp配置文件详解
  2. IOS开发资料汇总
  3. Git初步学习
  4. XML基础学习02&lt;linq to xml&gt;
  5. P3398 仓鼠找sugar
  6. linux win 通用的获取Mac的方法
  7. Java工具
  8. 让 Putty 保存密码,自动登陆的四种方法
  9. jQuery,javascript获得网页的高度和宽度
  10. nginx性能配置参数说明:
  11. javascript中使用md5函数
  12. (二)windows下安装PHPCMS V9
  13. N.O.W,O.R,N.E.V.E.R--12days to LNOI2015
  14. Mac下配置Maven环境变量
  15. cmd 更改计算机名
  16. IOS @proporty 关键字(一)retain strong
  17. selenium-判断元素是否可见(五)
  18. CDH5.15.1 hive 连接mongodb配置及增删改查
  19. ACM-ICPC 2018 南京赛区网络预赛 B The writing on the wall(思维)
  20. Oracle同义词(synonym)

热门文章

  1. 编译libvlc。。。
  2. 洛谷P4015 运输问题(费用流)
  3. jquery应用实例1:手风琴特效
  4. c++ sort函数的用法
  5. TortoiseSVN—Repo-browser
  6. solarwinds之配置系统管理(System manager)
  7. Arduino扫盲(持续添加中)
  8. iOS原生数据存储策略
  9. DOS下格式化移动硬盘
  10. AC Codeforces Round #499 (Div. 2) E. Border 扩展欧几里得