码迷,mamicode.com
首页 > 其他好文 > 详细

cookies和sessions

时间:2014-05-16 01:01:02      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   java   

response 为HttpResponse对象,request为HttpRequest对象

Cookies

    设置Cookies     response.set_cookie("cookie_key","value")

    获取Cookies  value = request.COOKIES["cookie_key"]
    删除Cookies  response.delete_cookie("cookie_key",path="/",domain=name)
   检测Cookies    if "cookie_name" is request.COOKIES

例子:

bubuko.com,布布扣
def test_cookies(request):
      if "test" in request.COOKIES:
            temp=request.COOKIES[test]
            return HttpResponse("cookies="+temp)
      else:
            response = HttpResponse("test")
            response.set_cookie("test","123456789")
            return response
bubuko.com,布布扣

Sessions

设置Sessions值     request.session[‘session_name‘] ="admin"
获取Sessions值  session_name = request.session["session_name"]
删除Sessions值    del request.session["session_name"]
检测是否操作session值    if "session_name" is request.session :

 

bubuko.com,布布扣
def test_sessions(request):
      if "test" in request.session:
            temp=request.session[test]
            return HttpResponse("session="+temp)
      else:   
            request.session[test]=123456789 
            response = HttpResponse("abcdef")
            return response
bubuko.com,布布扣

cookies和sessions,布布扣,bubuko.com

cookies和sessions

标签:style   blog   class   code   c   java   

原文地址:http://www.cnblogs.com/sklww/p/3730136.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!