首页 > Web开发 > 详细

使用bottle进行web开发(4):HTTPError

时间:2017-06-19 14:12:00      阅读:298      评论:0      收藏:0      [点我收藏+]
from bottle import error
@error(404)
def error404(error):
    return Nothing here, sorry

上述代码,是对404的定义,这里注意,有一个HTTPError,

HTTPError uses a predefined HTML template to build the body of the response. Instead of using HTTPError you can use response with the appropriate status code and body.

import json
from bottle import run, route, response

@route(/text)
def get_text():
    response.status = 400
    return Object already exists with that name

@route(/json)
def get_json():
    response.status = 400
    response.content_type = application/json
    return json.dumps({error: Object already exists with that name})

# Start bottle server.
run(host=0.0.0.0, port=8070, debug=True)

 

使用bottle进行web开发(4):HTTPError

原文:http://www.cnblogs.com/aomi/p/7048125.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!