登录cookie写法


def login(request):
if request == "GET":
return render(request,'login.html')
else:
user = request.POST.get('user')
pwd = request.POST.get('pwd')
if user == 'abc' and pwd == '123':
obj = redirect('/teacher/')
# obj.set_cookie('ticket', 'adklsajdlsdd',max_age=10,path="/")
obj.set_signed_cookie('ticket', '123123',salt="jjjjjj" ,max_age=10,path="/")
return obj
else:
return render(request,'login.html')

def teacher(request):
# tk = request.COOKIES.get('ticket')
tk = request.get_signed_cookie("ticket",salt="jjjjjj")
if not tk:
return redirect('/login/')



posted on 2020-09-12 13:40  Test-Billy  阅读(231)  评论(0编辑  收藏  举报