Cookie
一,添加
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)