获取cookie
request.COOKIE.GET
使用cookie
response.set-cookie
views.py
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def cookie_test(request):
r = HttpResponse("hello world")
r.set_cookie('lan', 'python')
r.set_cookie('framework','django')
print(request.COOKIES.get('lan'))
print(request.COOKIES.get('framework'))
return r
浏览器中观察cookie值
获取session
request.session.get
使用session
request.session
views.py
def session_test(request):
request.session['hello'] = 'world'
print(request.session.get('hello'))
return HttpResponse('hello session')
浏览器中查看session —— 加密显示