bottle---Python的轻量级http server,,相比于Django而言,
bottle---Python的轻量级http server,,相比于Django而言,
相比于Django而言,bottle显得非常轻量级。短短几行代码即可快速搭建一个简易的httpserver。提供了PythonWeb开发中需要的基本支持:URL路由,Request/Response对象封装,模板支持,与WSGI服务器集成支持。使用方法确实非常简便。```pythonimport simplejson as son
from bottle import Bottle, route, run, request, response, get, post
app = Buttle()
@app.route("/index.html")
def index():
return '<a href="/hello">Hello world</a>'
下边的例子根据/hello/xxx的url进行动态路由。
@app.route("/hello/:name")
def helloName(name):
page = request.GET.get('page', '1')return '<h1>Hello %s <br/>(%s)</h1>' % (name, page)
@app.get('/getRequest')
def getRequest():
return json.dumps({"status": 0, "data": "data"})
@app.post("/postRequest")
def postRequest():
data = request.formscmd = data.get('cmd', None)return json.dumps({"status": 0, "data": "data"})
if name == "main":
run(app, host='0.0.0.0', port=8080)```
相关内容
- 一个简单python ftp客户端代码,pythonftp客户端,#!/usr/bin
- Python3.4 邮件发送(含带中文附件),python3.4中文,None
- python通过ftp上传文件,,引入ftplib模块通过
- 帮同事写的一个切换数据库启动的小工具,同事切换数
- python检测远程udp端口是否打开,python检测udp端口,pytho
- 分析并输出Python代码依赖的库,输出python代码依赖,#!
- 文件按照日期命名,文件日期命名,# -*- coding
- python判断远程端口是否打开,python判断端口,python判断远
- python helloworld,helloworld,#!/usr/bin/e
- o(n)时间复杂度替换字符串中空格为%20,字符串,class o
评论关闭