Messa
Messa

Reputation: 25191

How to return redirect response from aiohttp.web server

How do I return a response with HTTP redirect in an aiohttp server handler?

Upvotes: 6

Views: 8905

Answers (1)

Messa
Messa

Reputation: 25191

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

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

The exception classes and their corresponding HTTP status codes: 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

Upvotes: 8

Related Questions