werkzeug.dump_cookie¶
Creates a new Set-Cookie header without the
Set-Cookie
prefix 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.
Parameters: - 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
example,
domain=".example.com"
will set a cookie that is readable by the domainwww.example.com
,foo.example.com
etc. Otherwise, a cookie will only be readable by the domain that set it. - secure – The cookie will only be available via HTTPS
- httponly – disallow JavaScript to access the cookie. This is an extension to the cookie standard and probably not supported by all browsers.
- charset – the encoding for unicode values.
- sync_expires – automatically set expires if max_age is defined but expires not.