如何在 Flask 中设置 HTTPONLY cookie

How to set an HTTPONLY cookie in Flask

我读 , but it's for setting secure cookies, but I'm trying to set HTTPONLY cookies. They both are kind-of-secure cookies, but differ in specs (read more).

cookie需要保护,因为它是关于用户的登录信息。

选中 Flask API 下的 set_cookie() (docs)。它提供了使用其 httponly 选项设置 HTTPONLY cookie 的选项。例如,以下代码将设置一个 HTTPONLY cookie:

set_cookie("name", value = "value", httponly = True)

Flask 提供了一个配置值 SESSION_COOKIE_HTTPONLY 来控制是否将 cookie 设置为仅限 http。但是,默认情况下,它设置为 True,因此除非明确设置为 False,否则 cookie 将仅为 http。