0

So when users of my site visit a.mysite.com, my flask server is setting the browser in their cookie via:

@app.route('/safe')
def tag_browser():
  response = redirect('/')
  response.set_cookie('hello', 'world')
  return response

This sets the cookie for a.mysite.com. However, I am interested to set the cookie for mysite.com

There is this thread: Share cookie between subdomain and domain which talks about how I can achieve the same effect wth

Set-Cookie: name=value; domain=mydomain.com

My problem is, how can I do so inside flask?

Community
  • 1
  • 1
Tinker
  • 3,082
  • 6
  • 25
  • 53

1 Answers1

1

Looks like the set_cookie function can get domain as param. From the documentation:

set_cookie(key, value='', max_age=None, expires=None, path='/', domain=None, secure=None, httponly=False)

domain – if you want to set a cross-domain cookie. For example, domain=".example.com" will set a cookie that is readable by the domain www.example.com, foo.example.com etc. Otherwise, a cookie will only be readable by the domain that set it.

yeger
  • 141
  • 1
  • 11