Cookie && Session
http 是无状态的,每一次发送过来依旧不知道他是谁 没有任何关联,这个时候就用到了cookie和session
客户端(cookie) 存储sessionid
1:给客户端设置cookie
response = HttpResponseRedirect(reverse('index'))
sessionid = str(uuid.uuid4())
response.set_cookie('mysessionid',sessionid)
2:设置session的值
requests.session[sessionid] = auth.name
return response
服务器(session)
cookie = requests.COOKIES.get('mysessionid',None)
session = requests.session.get(cookie,None)
requests.session['username'] = usermodel.name //就是代表当前当前用户session