标签:play span splay turn htm eth nbsp sse cookie
a. 简单应用
def login(request): if request.method=="GET": return render(request,"login.html") else: name = request.POST.get("name") password = request.POST.get("password") if name == "alex" and password == "123": obj = redirect("/classes/") obj.set_cookie("ticket","123456",max_age=10) return obj else: return redirect("/login/") def classes(request): sk = request.COOKIES print(sk) if not sk: return redirect("/login/")
b. 过期时间的两种格式
方式一: obj.set_cookie("ticket","123456",max_age=10) 方式二: import datetime from datetime import timedelta #时间的加减 ct = datetime.datetime.utcnow() #获取当前日期 v= timedelta(seconds=10) #10秒 value = ct + v obj.set_cookie("ticket","123456",expires=value)
c. 限制路径
obj.set_cookie("ticket","123456",max_age=10,path="/") #所有路径都可以访问 obj.set_cookie("ticket","123456",max_age=10,path="/class") #只有class访问
标签:play span splay turn htm eth nbsp sse cookie
原文地址:http://www.cnblogs.com/oyoui/p/7077090.html