8

I am writing a web server using the python aiohttp library.

How do I set a cookie and then redirect the user to another page in one response?

It's possible to redirect the user with aiohttp.web.HTTPSeeOther, but I can't find a way to attach cookies to it.

DXsmiley
  • 529
  • 5
  • 17

1 Answers1

12

Just set cookie value of the response.

import aiohttp
response = aiohttp.web.HTTPSeeOther(<location>)
response.cookies['test'] = '1'
return response
nmb.ten
  • 2,158
  • 1
  • 20
  • 18