如何从 aiohttp.web 服务器返回重定向响应

Mes*_*ssa 3 python aiohttp

如何在aiohttp服务器处理程序中使用 HTTP 重定向返回响应?

Mes*_*ssa 5

文档:http : //aiohttp.readthedocs.io/en/stable/web_quickstart.html#redirects

async def handler(request):
    raise web.HTTPFound('/redirect')
Run Code Online (Sandbox Code Playgroud)

异常类及其对应的 HTTP 状态代码:http : //aiohttp.readthedocs.io/en/stable/web_quickstart.html#exceptions

  * 300 - HTTPMultipleChoices
  * 301 - HTTPMovedPermanently
  * 302 - HTTPFound
  * 303 - HTTPSeeOther
  * 304 - HTTPNotModified
  * 305 - HTTPUseProxy
  * 307 - HTTPTemporaryRedirect
  * 308 - HTTPPermanentRedirect
Run Code Online (Sandbox Code Playgroud)