当前位置:网站首页>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 server2.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 respurl 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 siteApplication 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.
边栏推荐
猜你喜欢

第二届中国Rust开发者大会(RustChinaConf 2021~2022)线上大会正式开启报名

网络安全第二次作业

logback源码阅读(一)获取ILoggerFactory、Logger

Sentinel源码(四)(滑动窗口流量统计)

Object detection scene SSD-Mobilenetv1-FPN

世界上最大的开源基金会 Apache 是如何运作的?

ZABBIX配置邮件报警和微信报警

【ROS】工控机的软件包不编译

Interview | with questions to learn, Apache DolphinScheduler Wang Fuzheng

shell脚本“画画”
随机推荐
[ROS](06)ROS通信 —— 话题(Topic)通信
mysql的case when如何用
Supervision strikes again, what about the market outlook?2021-05-22
微信小程序-最近动态滚动实现
线代:已知一个特征向量快速求另外两个与之正交的特征向量
动手学ocr(一)
Flask框架的搭建及入门
网络安全第三次作业
此次519暴跌的几点感触 2021-05-21
[ROS](03)CMakeLists.txt详解
RKMPP API安装使用总结
【ROS】工控机的软件包不编译
Mysql's case the when you how to use
第二讲 软件生命周期
deal!It's July 30th!
第七单元 ORM表关系及操作
8576 顺序线性表的基本操作
【Tensorflow】AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'
Geoffery Hinton:深度学习的下一个大事件
如何解决mysql服务无法启动1069