一、cookie session token
1 cookie:客戶端瀏覽器上的鍵值對 2 session:存在服務端的鍵值對 3 token: 服務端簽發的加密字串 (加密的鍵值對,如果放在客戶端瀏覽器上,它就叫cookie) 比如: head.{name:lqz,age:18}.eseetsweasdca base64加碼后變成: asdfasfd.asdfasdf.asdfasdfaeraew 后端校驗: 用這個token去查我的賬戶余額,向銀行發請求,銀行校驗通過,是銀行給你的,---》回傳你的余額 比如:head.{name:lili,age:18}.eseetsweasdca 服務端可以匹配上,允許訪問 eseetsweasdca的生成跟{name:lili,age:18}對應的 但是head.{name:egon,age:18}.eseetsweasdca name變了后服務端就匹配不成功了
二、django中cookie的使用
def cookie_test(request): # 瀏覽器向我這個地址發一個請求,就在瀏覽器寫入 name = zhangsan obj=HttpResponse('ok') obj.set_cookie('name','zhangsan') # 寫入到瀏覽器了,在http回應頭里:cookie: name=zhangsan obj.set_cookie('age','19') # 寫入到瀏覽器了,在http回應頭里:cookie: age=19 return obj def get_cookie(request): print(request.COOKIES) print(request.COOKIES.get('name')) return HttpResponse('我拿了你傳過來的cookie') def delete_cookie(request): obj=HttpResponse('我刪掉了你 name 這個cookie ') obj.delete_cookie('name') return obj
三、django中session的使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/184384.html
標籤:架構設計
上一篇:入門到精通,阿里架構師撰寫的兩份MySQL技術寶典,已經超神
下一篇:PHP設計模式—配接器模式
