您的位置:首页 > 编程语言 > Python开发

bottle框架学习(六)之错误与重定向

2015-06-21 13:57 513 查看
[root@ju bottle]# cat error.py
#!/usr/bin/env python
#coding=utf-8
from bottle importroute,run,error,abort,redirect

#访问页面出错,Bottle会显示一个默认的错误页面,提供足够的debug信息。你也可以使用error()函数来自定义你的错误页面
@error(404)
def error404(error):
return '访问出错啦!' #一般返回一个错误页面模版,这里为了简单起见,就不写了

@route('/hello')
def hello():
return 'hello!'

@route('/redtest')
def redtest():
redirect('/hello') #访问/redtest的时候,会被重定向到/hello页面

@route('/abort404')
def abort404():
abort(404)  #当访问/aborttest时,会触发404错误

@route('/abort500')
def abort500():
abort(500)  #当访问/aborttest时,会触发500错误

run(host='0.0.0.0',port=8000)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息