dump_cookie(key, value='', max_age=None, expires=None, path='/', domain=None, secure=False, httponly=False, charset='utf-8', sync_expires=True)¶
Creates a new Set-Cookie header without the
Set-Cookieprefix The parameters are the same as in the cookie Morsel object in the Python standard library but it accepts unicode data, too.
On Python 3 the return value of this function will be a unicode string, on Python 2 it will be a native string. In both cases the return value is usually restricted to ascii as the vast majority of values are properly escaped, but that is no guarantee. If a unicode string is returned it’s tunneled through latin1 as required by PEP 3333.
The return value is not ASCII safe if the key contains unicode characters. This is technically against the specification but happens in the wild. It’s strongly recommended to not use non-ASCII values for the keys.
- max_age – should be a number of seconds, or None (default) if the cookie should last only as long as the client’s browser session. Additionally timedelta objects are accepted, too.
- expires – should be a datetime object or unix timestamp.
- path – limits the cookie to a given path, per default it will span the whole domain.
- domain – Use this if you want to set a cross-domain cookie. For
domain=".example.com"will set a cookie that is readable by the domain
foo.example.cometc. Otherwise, a cookie will only be readable by the domain that set it.
- secure – The cookie will only be available via HTTPS
- charset – the encoding for unicode values.
- sync_expires – automatically set expires if max_age is defined but expires not.