文章目录
参考资料
B站网课:点击蓝色字体跳转
会话保持
Http的请求与相应对应着家和商店之间的交易,家相当于浏览器,商店相当于服务器,通过办会员卡的方式可以保存交易记录。
Cookies
views.py
c
def set_cookies(request):
resp = HttpResponse('set cookies is ok')
resp.set_cookie('uuname','syw',500)
return resp
def get_cookies(request):
value = request.COOKIES.get('uuname')
return HttpResponse('value is %s'%(value))
urls.py
c
path('set_cookies',views.set_cookies),
path('get_cookies',views.get_cookies),
Session
views.py
c
def set_session(request):
request.session['uname']='czn'
return HttpResponse('set session is ok')
def get_session(request):
value=request.session['uname']
return HttpResponse('session value is %s'%(value))
urls.py
c
path('set_session',views.set_session),
path('get_session',views.get_session),