# 设置session

def setSession(request):
request.session['username'] = 'ruan'
request.session['isLogin'] = True
return HttpResponse('OK')


# 获取session
def GetSession(request):
isLogin = request.session.get('isLogin')
if not isLogin:
return redirect('/login/')
username = request.session.get('username')


# 删除session
  request.session.flush()    #删除所有session
  #del request.session['username'] #删除key为username的session   return HttpResponse('清除成功')

 PS:在django中,session默认的过期时间是两周