bottle---Python的轻量级http server
发布时间:2020-05-28 23:38:13 所属栏目:Python 来源:互联网
导读:bottle---Python的轻量级http server
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 相比于Django而言,bottle显得非常轻量级。短短几行代码即可快速搭建一个简易的http server。提供了 Python Web开发中需要的基本支持:URL路由,Request/Response对象封装,模板支持,与WSGI服务器集成支持。使用方法确实非常简便。import 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.forms
cmd = data.get('cmd',None)
return json.dumps({"status": 0,"data": "data"})
if __name__ == "__main__":
run(app,host='0.0.0.0',port=8080)
以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
