0Pricing
Flask Academy · Lesson

Set Custom Cookies on a Response

Write cookies with set_cookie and options.

Cookies Beyond Sessions

Sometimes you want your own cookie, separate from the session, to remember a theme or a preference for a visitor. 🍪

You Need a Response

Cookies are written onto a response object. So first build one with make_response instead of returning a plain string.

from flask import make_response
resp = make_response('Hi there')

All lessons in this course

  1. Set and Read the session Dict
  2. The SECRET_KEY and Signed Cookies
  3. Set Custom Cookies on a Response
  4. Flash Messages Between Requests
← Back to Flask Academy