bottle框架学习(二)静态文件请求、404错误与URL转向
2018-03-13 22:37
519 查看
返回静态文件内容
return static_file(filename,root=”,mimetype=”)from bottle import route,run,static_file @route('/static/<filename:path>') def index(filename): return static_file(filename,root="static/") run(host='localhost',port=80,debug=True,reloader=True)
打开浏览器http://localhost/static/img.gif
强制下载文件
return static_file(filename,root=”“,download=True)download=True表示用服务器上的文件名进行保存
download=”my.jpg”表示下载保存的文件名
from bottle import route,run,static_file @route('/static/<filename:path>') def index(filename): return static_file(filename,root="static/") @route('/d1/<filename:path>') def d1(filename): return static_file(filename, root="static/",download="demo.gif") run(host='localhost',port=80,debug=True,reloader=True)
打开浏览器http://localhost/d1/img.gif
指定404页面
@error(404)装饰错业务函数业务函数的参数列表中要包含一个接受错误值的参数
from bottle import route,run,static_file,error @route('/static/<filename:path>') def index(filename): return static_file(filename,root="static/") @route('/d1/<filename:path>') def d1(filename): return static_file(filename, root="static/",download="demo.gif") @error(404) def err(err): return "亲,你要的页面丢失了" run(host='localhost',port=80,debug=True,reloader=True)
URL转向
转向错误abort(404,’error_info’)from bottle import route,run,static_file,error,abort @route('/static/<filename:path>') def index(filename): return static_file(filename,root="static/") @route('/d1/<filename:path>') def d1(filename): return static_file(filename, root="static/",download="demo.gif") @error(404) def err(err): return "亲,你要的页面丢失了404" @error(500) def err(err): return "亲,你要的页面丢失了500" @route('/abort') def abort_test(): abort(500,'error_info') run(host='localhost',port=80,debug=True,reloader=True)
调用redirect(other url)函数
from bottle import route,run,static_file,error,abort,redirect @route('/static/<filename:path>') def index(filename): return static_file(filename,root="static/") @route('/d1/<filename:path>') def d1(filename): return static_file(filename, root="static/",download="demo.gif") @error(404) def err(err): return "亲,你要的页面丢失了404" @error(500) def err(err): return "亲,你要的页面丢失了500" @route('/abort') def abort_test(): abort(500,'error_info') @route('/') def index(): return "index Page" @route('/login/<name>') def login(name): if name == "abc": redirect('/') else: redirect('/login') run(host='localhost',port=80,debug=True,reloader=True)
相关文章推荐
- play_scala框架学习07 静态文件
- Django ====> 1.4版本静态文件路径设置--MEDIA_ROOT,MEDIA_URL, STATIC_ROOT, STATIC_URL学习
- django中url,静态文件,POST请求的配置
- Laravel框架学习(Request请求数据、Cookie、文件上传)
- Python的Bottle框架中返回静态文件和JSON对象的方法
- Python的Bottle框架中返回静态文件和JSON对象的方法
- bottle框架学习(三)获取GET,POST请求的参数
- 关于PHP-Zend framework2 框架 学习过程。 阅前须知: ZF2中的配置文件是可以静态文件配置来注册和通过相关函数动态注册。 1.EventManager(事件驱动),关于事件驱动,在ZF2相关资料没有详细说明,可以参考ANDROID的事件驱动,MFC的消息响应/事件驱动。
- bottle框架学习(六)实现HTTP上传文件
- django中url,静态文件,POST请求的配置 分类: Python 2015-06-01 17:00 789人阅读 评论(0) 收藏
- django中url,静态文件,POST请求的配置
- bottle框架学习(五)之文件的下载与上传
- Http学习之使用HttpURLConnection发送post请求深入
- HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本 因而将无法由静态文件处理程序来处理
- 使用Django来处理对于静态文件的请求
- 解决“HTTP/1.1 405 Method not allowed”问题,让静态文件响应POST请求[原创]
- 用URL请求做文件上传
- WIN7(x64) IIS7.5 404.17错误:请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。
- HTTP错误404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理
- Win7 HTTP 错误 404.17 – Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。