django-cookies 和session
会话
会话定义
cookies
cookies的特点
cookies的使用
veiws.py
def set_cookie(request):
resp=HttpResponse('set_cookies')
resp.set_cookie('username','123456',5000)
return resp
页面显示内容
示例:
cookies删除获取
session
session的定义
session settings配置
session的使用
def set_sessions(request):
request.session['uname']='SCARF'
return HttpResponse('session is ok')
def get_sessions(request):
value=request.session['uname']
return HttpResponse('value值为%s'%(value))
session时长默认两周
session配置修改
mysql> select * from django_session \G:
*************************** 1. row ***************************
session_key: fh8ovkc0hwn531u6vzkqj1pc02mdqgf3
session_data: OGQ1YTVkMTY4NTRiMzBiN2Y4Y2U3NjYzMTA2ZjkxYzlmMWJiODM3Nzp7InVuYW1lIj
oiU0NBUkYifQ==
expire_date: 2021-08-29 04:08:44.994460
*************************** 2. row ***************************
session_key: y36n8w8sjv11695j7j8wavswgu9oddb0
session_data: OGQ1YTVkMTY4NTRiMzBiN2Y4Y2U3NjYzMTA2ZjkxYzlmMWJiODM3Nzp7InVuYW1lIj
oiU0NBUkYifQ==
expire_date: 2021-08-29 04:13:51.602997
2 rows in set (0.00 sec)