# 设置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默认的过期时间是两周
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Django设置/获取/删除session - Python技术站