Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return redirect response from aiohttp.web server

Tags:

python

aiohttp

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

like image 240
Messa Avatar asked Aug 18 '17 20:08

Messa


1 Answers

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
like image 122
Messa Avatar answered Nov 01 '22 13:11

Messa