views.py
def set_cookie(request):
#设置cookie需要HttpResponse对象
response = HttpResponse('设置cookie')
response.set_cookie('num',1)
return response
def get_cookie(request):
num = request.COOKIES['num']
return HttpResponse(num)
我们能够看到 已经成功设置了cookie并被保存在浏览器,接下来就是取出cookie
request.COOKIES['num']