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

时间:2017-08-18 20:21:09

标签: python aiohttp

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

1 个答案:

答案 0 :(得分:4)

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

async def handler(request):
    raise web.HTTPFound('/redirect')

异常类及其相应的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