gpt4 book ai didi

python - 在 Bottle 中设置 HTTP 状态码?

转载 作者:IT老高 更新时间:2023-10-28 20:43:47 26 4
gpt4 key购买 nike

如何在 Bottle 中设置响应的 HTTP 状态码?

from bottle import app, run, route, Response

@route('/')
def f():
Response.status = 300 # also tried `Response.status_code = 300`
return dict(hello='world')

'''StripPathMiddleware defined:
http://bottlepy.org/docs/dev/recipes.html#ignore-trailing-slashes
'''

run(host='localhost', app=StripPathMiddleware(app()))

如你所见,输出没有返回我设置的 HTTP 状态码:

$ curl localhost:8080 -i
HTTP/1.0 200 OK
Date: Sun, 19 May 2013 18:28:12 GMT
Server: WSGIServer/0.1 Python/2.7.4
Content-Length: 18
Content-Type: application/json

{"hello": "world"}

最佳答案

我相信你应该使用 response

来自 Bottle 的进口响应; response.status = 300

关于python - 在 Bottle 中设置 HTTP 状态码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16638117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com