- Python Falcon教程
- Python Falcon - 主页
- Python Falcon - 简介
- Python Falcon - 环境设置
- Python Falcon - WSGI 与 ASGI
- Python Falcon - Hello World(WSGI)
- Python Falcon - 女服务员
- Python Falcon - ASGI
- 蟒蛇Falcon - Uvicorn
- Python Falcon - API 测试工具
- 请求与响应
- Python Falcon - 资源类
- Python Falcon - 应用程序类
- Python Falcon - 路由
- Falcon - 后缀响应者
- Python Falcon - 检查模块
- Python Falcon - Jinja2 模板
- Python Falcon - cookie
- Python Falcon - 状态代码
- Python Falcon - 错误处理
- Python Falcon - 钩子
- Python Falcon - 中间件
- Python Falcon - CORS
- Python Falcon - Websocket
- Python Falcon - Sqlalchemy 模型
- Python Falcon - 测试
- Python Falcon - 部署
- Python Falcon 有用资源
- Python Falcon - 快速指南
- Python Falcon - 有用的资源
- Python Falcon - 讨论
Python Falcon - 状态代码
默认情况下,HTTP 服务器对客户端请求的响应具有 200 OK 状态。Falcon 提供了自己的状态常量列表,以提高便利性和可读性。
例如,200 OK 状态代码表示为:
resp.status = falcon.HTTP_OK
这些预定义的 Falcon 常量可以避免拼写错误,并减少准备响应时必须创建的字符串对象的数量。然而,从 Falcon 3.0 版本开始,也允许使用裸int代码。
resp.status = 200
对于 ASGI 申请,相同的状态代码适用。
下面列出了 Falcon 库中定义的一些状态代码 -
信息代码
HTTP_继续 = HTTP_100
HTTP_SWITCHING_PROTOCOLS = HTTP_101
HTTP_处理 = HTTP_102
成功状态代码
HTTP_OK = HTTP_200
HTTP_CREATED = HTTP_201
HTTP_ACCEPTED = HTTP_202
HTTP_NON_AUTHORITATIVE_INFORMATION = HTTP_203
HTTP_NO_CONTENT = HTTP_204
HTTP_RESET_CONTENT = HTTP_205
HTTP_PARTIAL_CONTENT = HTTP_206
HTTP_MULTI_STATUS = HTTP_207
HTTP_ALREADY_REPORTED = HTTP_208
HTTP_IM_USED = HTTP_226
重定向错误代码
HTTP_MULTIPLE_CHOICES = HTTP_300
HTTP_MOVED_PERMANENTLY = HTTP_301
HTTP_FOUND = HTTP_302
HTTP_SEE_OTHER = HTTP_303
HTTP_NOT_MODIFIED = HTTP_304
HTTP_USE_PROXY = HTTP_305
HTTP_TEMPORARY_REDIRECT = HTTP_307
HTTP_PERMANENT_REDIRECT = HTTP_308
客户端错误代码
HTTP_BAD_REQUEST = HTTP_400
HTTP_UNAUTHORIZED = HTTP_401 #“未经身份验证”
HTTP_PAYMENT_REQUIRED = HTTP_402
HTTP_FORBIDDEN = HTTP_403 #“未经授权”
HTTP_NOT_FOUND = HTTP_404
HTTP_METHOD_NOT_ALLOWED = HTTP_405
HTTP_NOT_ACCEPTABLE = HTTP_406
HTTP_PROXY_AUTHENTICATION_REQUIRED = HTTP_407
HTTP_REQUEST_TIMEOUT = HTTP_408
HTTP_冲突 = HTTP_409
服务器错误代码
HTTP_INTERNAL_SERVER_ERROR = HTTP_500
HTTP_NOT_IMPLMENTED = HTTP_501
HTTP_BAD_GATEWAY = HTTP_502
HTTP_SERVICE_UNAVAILABLE = HTTP_503
HTTP_GATEWAY_TIMEOUT = HTTP_504
HTTP_HTTP_VERSION_NOT_SUPPORTED = HTTP_505
HTTP_INSUFFICIENT_STORAGE = HTTP_507
HTTP_LOOP_DETECTED = HTTP_508
HTTP_NETWORK_AUTHENTICATION_REQUIRED = HTTP_511