获取Cookie
request.COOKIES[key]
request.COOKIES.get(key)
# 普通cookie是明文传输的,可以直接在客户端直接打开,所以需要加盐,解盐之后才能查看
request.get_signed_cookie(key, default=RAISE_ERROR, salt='', max_age=None)
参数:
- default: 默认值
- salt: 加密盐
- max_age: 后台控制过期时间
设置cookie
在对象返回给客户端之前,设置cookie
response = redirect('/page/')
response.set_cookie(key, value='', max_age=None, expires=None, path='/', domain=None, secure=None, httponly=False)
response.set_signed_cookie(key,value,salt='加密盐',...)
参数:
- key:键
- value="":值
- max_age=None:cookie的生命长度,默认为None,浏览器关闭cookie立即失效
- expires=None:cookie过期时间时间点,默认为None,浏览器关闭cookie立即失效
- path=’/’:Cookie生效的路径,/ 表示根路径。根路径的cookie可以被任何url的页面访问
- domain=None:默认值为None,设置该 Cookie 的网页所在的域名None
- secure=False:用来设置 Cookie 只在确保安全的请求中才会发送。当请求是 HTTPS 或者其他安全协议时,包含 secure 选项的 Cookie 才能被保存到浏览器或者发送至服务器。
- httponly=False:为True时,只能在HTTP协议中传输,无法通过 JavaScript 获取
Reference
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper