当前位置:网站首页>Unit 5 Hold Status
Unit 5 Hold Status
2022-08-02 14:18:00 【czy1206527605】
Cookie
1. The role of cookies
When the client accesses, the server will generate a `Cookie` key-value pair data for the client and send it to the client through a `Response` response.The next time the client continues to access the same server, the browser client will send this `Cookie` value to the server
2.Application of cookies
views layer
**Set and get cookies**Get: You can get it directly through getclass CookieView(View):# If there is no cookie, set the cookie; if there is, display the current cookiedef get(self, request):cookie_data = request.COOKIES.get('shenfen')if cookie_data is None:resp = HttpResponse('Set cookie')resp.set_cookie('shenfen','kjdl')return respelse:return HttpResponse(f"The current cookie information is {cookie_data}")**Delete COOKIE**Delete: delete the specified key and corresponding valueclass DelCookieView(View):# delete cookiesdef get(self, request):resp = HttpResponse("Delete cookie information")resp.delete_cookie('shenfen')return resp
url layer
path('cookie/', views.CookieView.as_view()),path('delcookie/', views.DelCookieView.as_view()),
Session
1. Advantages of cookies
Advantages:1. It runs on the server side, which is more secure than cookies2. The data will not be lost and can survive the entire session.Disadvantage:1. Cookies can keep the state of the user when they visit the site
Application of 2.session
views layer
**Set and get session**Get: You can get it directly through getclass SessionView(View):# If the session does not exist, generate a session; if it exists, return session informationdef get(self, request):session_data = request.session.get('money')if session_data is None:request.session['money'] = '10000000'return HttpResponse('set session')else:return HttpResponse(f"session information is: {session_data}")**Delete session**class DelSessionView(View):def get(self, request):if request.session.get('money') is None:return HttpResponse('session does not exist')else:del request.session['money']return HttpResponse("session has been deleted")
url layer
path('session/', views.SessionView.as_view()),path('delsession/', views.DelSessionView.as_view())
CSRF
csrf's attack process
How to prevent csrf attacks
Add inside the code:{% csrf_token %}
Today's Error Summary
When doing homework,The password in the user table that stores the account password in the game database should be defined by the CharField type. I used the
value type.The password has been wrong.
边栏推荐
猜你喜欢
目标检测场景SSD-Mobilenetv1-FPN
[ROS]roscd和cd的区别
第二届中国Rust开发者大会(RustChinaConf 2021~2022)线上大会正式开启报名
Break the limit of file locks and use storage power to help enterprises grow new momentum
第五单元 保持状态
Some impressions of the 519 plummet 2021-05-21
跑yolov5又出啥问题了(1)p,r,map全部为0
RKMPP库快速上手--(一)RKMPP功能及使用详解
Sentinel源码(四)(滑动窗口流量统计)
Object detection scene SSD-Mobilenetv1-FPN
随机推荐
第七单元 ORM表关系及操作
关于市场后市的发展预测? 2021-05-23
uview 2.x版本 tabbar在uniapp小程序里头点击两次才能选中图标
8580 合并链表
网络安全第四次作业
理解TCP长连接(Keepalive)
第六单元 初识ORM
[ROS]ROS常用工具介绍(待续)
[ROS](05)ROS通信 —— 节点,Nodes & Master
How to solve 1045 cannot log in to mysql server
一维卷积神经网络_卷积神经网络的基础知识「建议收藏」
IDEA打包jar包
定了!就在7月30日!
无序数组排序并得到最大间隔
MySQL数据库语法格式
MobileNet ShuffleNet & yolov5替换backbone
Flask框架的搭建及入门
目标检测场景SSD-Mobilenetv1-FPN
Object detection scene SSD-Mobilenetv1-FPN
Go语言初始