Django之cookie和session

一,添加

python 复制代码
response = redirect(reverse('index'))

response.set_cookie('userid', user.id, expires=
            datetime.datetime.now() + datetime.timedelta(days=7)
                                )

二,获取

python 复制代码
userid = request.COOKIE.get('userid',0)

三,删除

python 复制代码
response = redirect(reverse('index'))
response.delete_cookie('userid')

Session

一,添加

python 复制代码
request.session['userid'] = user.id
request.session.set_expiry(7*24*3600)

二,获取

python 复制代码
userid = request.session.get('userid',0)

三,删除

python 复制代码
sessionkey = request.session.session_key
request.session.delete(sessionkey)
相关推荐
minebmw71 天前
Oracle 19.29 中 ORA-00600 [4193] 错误完全解析与恢复指南
数据库·oracle
bloglin999991 天前
scp、rsync远程文件同步
linux·运维·服务器
迦南的迦 亚索的索1 天前
LINUX环境
linux·运维·服务器
yuanjj881 天前
linux下调试域格CLM920 NC5等9x07平台模块 QMI拨号
linux·运维·服务器
m0_377618231 天前
Golang怎么连接MySQL数据库_Golang MySQL连接教程【总结】
jvm·数据库·python
IMPYLH1 天前
Linux 的 printenv 命令
linux·运维·服务器·bash
SilentSamsara1 天前
SSH 远程管理:密钥登录 + 隧道转发,一次性配置好
linux·运维·服务器·ubuntu·centos·ssh
weixin_586061461 天前
C#怎么通过反射获取类属性_C#如何动态读取元数据【进阶】
jvm·数据库·python
Pluto_CSND1 天前
PostgreSQL 聚合函数总览
数据库·postgresql
资深数据库专家1 天前
总账EBS 应用服务器1 的监控分析
java·网络·数据库