cookie是保存在浏览器本地上的一组组键值对;
特性:
command + shift + delete
from django.shortcuts import render, redirect, HttpResponse from functools import wraps # Create your views here. def login(request): if request.method == 'POST': user = request.POST.get('username') pwd = request.POST.get('pwd') print(user, pwd) if user == 'aaa' and pwd == 'xxxx': res = redirect('/index/') res.set_cookie('islogin', '1') return res else: error = '用户名密码错误' return render(request, 'login.html', locals()) def login_required(func): @wraps(func) def inner(request, *args, **kwargs): print(request.COOKIES) is_login = request.COOKIES.get('islogin') print(is_login, type(is_login)) if is_login != '1': # 没有登陆,跳转到登陆页面 return redirect('/') ret = func(request, *args, **kwargs) return ret return inner @login_required def index(request): print(request.COOKIES) return render(request, 'index.html')