首页 / 更多教程 / bottle框架代码的组织
bottle框架代码的组织
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了bottle框架代码的组织,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2293字,纯文字阅读大概需要4分钟。
内容图文
![bottle框架代码的组织](/upload/InfoBanner/zyjiaocheng/1236/49359645f0a14d18933016ce0efe0fd8.jpg)
#!/usr/bin/python # -*- coding: UTF-8 -*- import bottle #bottle.debug(True) import time,sys,os import MySQLdb from bottle import route,error,template,request,response from bottle import get,post from bottle import static_file from bottle import view bottle.TEMPLATES.clear() #template using view @route("/template_file") @route("/template_file/<name>") @view("hello_template") def hello(name="world"): return dict(name=name) #environ @route("/ipaddr") def ipaddr(): ip = request.environ.get("REMOTE_ADDR") #return ip return str(request.environ) #template @route("/hello/<name>") def test(name="Stangeer"): return template("hello {{name}},8888",name=name) #reponse application/json,濡傛灉杩斿洖瀛楀吀锛宑ontent type浼氳嚜鍔ㄨ浆涓? applicaton/json @route("/json") def json(): return {"name":"scj","age":34,"ch_name":"鏉板厠"} #dynamic routes @route(‘/greet/<name>‘) def greet(name): return "hello,"+name #get method @get(‘/gettest‘) def gettest(): return request.query.get(‘name‘)+request.query.get(‘age‘) #post method @post(‘/posttest‘) def post_test(): return request.forms.get(‘name‘)+request.forms.get(‘age‘) #get post merged method by using route @route(‘/routemethod‘) def routemethod(): v = request.query.get(‘name‘) v2 = request.forms.get(‘name‘) if v is None: return "get:none" if v2 is None: return "post:none" return "get:"+request.query.get(‘name‘)+","+request.forms.get(‘name‘) #static file @route(‘/statictest/<filepath:path>‘) def static_test(filepath): return static_file(filepath,root=‘/var/www/html‘) #not found page @error(404) def error404(error): return "12璁块棶鐨勯〉闈笉瀛樺湪404" ‘‘‘甯哥敤鍑芥暟 abort(401,"sorry,access denied")#鐩存帴鎶ラ敊 redirect("/right/url")#閲嶅畾鍚? response.set_header("Content-Language","en") response.set_header(‘Set-Cookie‘, ‘name=value‘) response.add_header(‘Set-Cookie‘, ‘name2=value2‘) #get method id = request.query.id id = request.query.get("id") #cookie str_temp = request.get_cookie("visited")#if no cookie,return None str_temp = request.cookies.get("visited","defaultValue") response.set_cookie("token", "12344321",max_age=100,path="/") str_temp = request.get_cookie("visited",secret="mykey")#鍔犲瘑鑾峰彇 response.set_cookie("token", "12344321",max_age=100,path="/",secret="mykey")#鍔犲瘑璁剧疆 ‘‘‘
原文:https://www.cnblogs.com/dongfangchun/p/9241423.html
内容总结
以上是互联网集市为您收集整理的bottle框架代码的组织全部内容,希望文章能够帮你解决bottle框架代码的组织所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。