2024-05-29 10:58:13 发布
网友
在找了一段时间并询问: https://gitter.im/timothycrosley/hug 我找不到解决办法。在
我要寻找的是一种返回自定义http代码的方法,比如说204,以防在get端点满足一个条件。 路由问题的解释是here
get
但我似乎找不到一种方法来返回除了200以外的任何其他代码
在他们的回购中找到了一个例子(https://github.com/berdario/hug/blob/5470661c6f171f1e9da609c3bf67ece21cf6d6eb/examples/return_400.py)
import hug from falcon import HTTP_400 @hug.get() def only_positive(positive: int, response): if positive < 0: response.status = HTTP_400
基于jbasko的答案,hugs似乎希望status是HTTP状态代码的文本表示。在
例如:
>> print (HTTP_400) Bad Request
因此,对于更完整的示例,您可以使用所有回答的dict:
我已经编译了所有状态代码的列表in this gist
可以引发falcon HTTPError,例如:
raise HTTPInternalServerError
查看更多详细信息:https://falcon.readthedocs.io/en/stable/api/errors.html
在他们的回购中找到了一个例子(https://github.com/berdario/hug/blob/5470661c6f171f1e9da609c3bf67ece21cf6d6eb/examples/return_400.py)
基于jbasko的答案,hugs似乎希望status是HTTP状态代码的文本表示。在
例如:
因此,对于更完整的示例,您可以使用所有回答的dict:
^{pr2}$我已经编译了所有状态代码的列表in this gist
可以引发falcon HTTPError,例如:
raise HTTPInternalServerError
查看更多详细信息:https://falcon.readthedocs.io/en/stable/api/errors.html
相关问题 更多 >
编程相关推荐