本文整理汇总了Python中bottle.HTTPResponse.add_header方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse.add_header方法的具体用法?Python HTTPResponse.add_header怎么用?Python HTTPResponse.add_header使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle.HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse.add_header方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_response_from_exception
# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import add_header [as 别名]
def get_response_from_exception(excep, exception_mapping):
status = exception_mapping.get(excep.__class__, None)
if status is None:
status = 500
ret = HTTPResponse(status=status, body=str(excep))
ret.add_header("Content-Type", "text/plain")
return ret
示例2: send_response
# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import add_header [as 别名]
def send_response(code, message=None):
r = HTTPResponse(status=code)
r.add_header('Access-Control-Allow-Origin', '*')
r.set_header('Content-Type', 'application/json')
if message is None:
r.set_header('Content-Type', 'text/plain')
elif type(message) is str:
e = {'error': message}
r.body = json.dumps(e)
elif type(message) is dict:
r.body = json.dumps(message)
else:
r.body = message
return r
示例3: options_group
# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import add_header [as 别名]
def options_group(gid):
r = HTTPResponse(status=200)
r.add_header('Access-Control-Allow-Origin', '*')
r.add_header('Access-Control-Allow-Methods', 'GET, DELETE, PUT')
return r
示例4: post
# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import add_header [as 别名]
def post(self):
m = self.insert(request.json)
response = HTTPResponse(status=201, body=json.dumps(m.to_dict()))
response.content_type = "application/json"
response.add_header("Location", "{}/{}".format(self.base, m.id))
return response