@app.route('/')
def index():
# return '123'
res = Response("首页")
res.set_cookie('abc', '123', max_age=3) # key=abc, value=123, 3s后过期
''' set_cookie()源码
def set_cookie(
self,
key,
value="",
max_age=None, # 失效时间
expires=None, # datetime形式的失效时间
path="/", # 在该路径下才能设置cookie
domain=None, # 域名限制
secure=False, # 仅可通过HTTPS使用
httponly=False,
samesite=None,
):
:param key: the key (name) of the cookie to be set.
:param value: the value of the cookie.
:param 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.
:param expires: should be a `datetime` object or UNIX timestamp.
:param path: limits the cookie to a given path, per default it will
span the whole domain.
:param 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.
:param secure: If `True`, the cookie will only be available via HTTPS
'''
return res
原创文章 81获赞 13访问量 9024
关注
私信
展开阅读全文
作者:越过山丘,佳人等候