django cookie

时间:2025-01-30 22:37:08

设置:auth.login(request, user)
                response = HttpResponseRedirect(reverse("index"))
                response.set_cookie('xiang', username, 3600)
                return response

获取:

  def index(req):

    username = req.COOKIES.get('username','')

    return render_to_response('index.html' ,{'username':username})

删除:

  def logout(req):

    response = HttpResponse('logout !!')
#清理cookie里保存username

    response.delete_cookie('username')

    return response

使用:    

    {{username}}

session与cookie

http://www.cnblogs.com/lhj588/archive/2011/10/27/2226976.html