栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

django配置-SESSION

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

django配置-SESSION

django配置-SESSION_cookie_SECURE = True

官方参考:https://docs.djangoproject.com/en/dev/topics/security/

#transfer cookie with https 
SESSION_cookie_SECURE = True

If a browser connects initially via HTTP, which is the default for most browsers, it is possible for existing cookies to be leaked. For this reason, you should set your SESSION_cookie_SECURE and CSRF_cookie_SECURE settings to True. This instructs the browser to only send these cookies over HTTPS connections. Note that this will mean that sessions will not work over HTTP, and the CSRF protection will prevent any POST data being accepted over HTTP (which will be fine if you are redirecting all HTTP traffic to HTTPS).
如果浏览器最初通过 HTTP(大多数浏览器的默认设置)进行连接,则现有 cookie 可能会泄露。 因此,您应该将 SESSION_cookie_SECURE 和 CSRF_cookie_SECURE 设置设为 True。 这会指示浏览器仅通过 HTTPS 连接发送这些 cookie。 请注意,这意味着会话将无法通过 HTTP 工作,并且 CSRF 保护将阻止通过 HTTP 接受任何 POST 数据(如果您将所有 HTTP 流量重定向到 HTTPS,这会很好)。

这个配置项,我们一般在开发测试环境使用HTTP的话,我们需要把SESSION_cookie_SECURE 设置为False

SESSION_cookie_SECURE = True的话,接口返回的 set-cookie 字段是 secure 属性为 true,开发联调时,前端目前起本地服务如果没有用 https,浏览器的安全限制会导致本地 cookie 没有插进去。

#transfer cookie with https 
SESSION_cookie_SECURE = False

经过测试,如果你开发测试环境使用http访问django, SESSION_cookie_SECURE 还是True的话,

就会报:
400 Bad Request

HTTP 400 Bad Request 响应状态码表示由于语法无效,服务器无法理解该请求。 客户端不应该在未经修改的情况下重复此请求。
状态

400 Bad Request

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/304241.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号