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

RHCE第一天作业

不精确微分/不完全微分(Inexact differential/Imperfect differential)

IDEA打包jar包

MobileNet ShuffleNet & yolov5替换backbone

How to solve mysql service cannot start 1069

动手学ocr(一)

8581 线性链表逆置

Configure zabbix auto-discovery and auto-registration.

Flask项目的完整创建 七牛云与容联云

Interview | with questions to learn, Apache DolphinScheduler Wang Fuzheng
随机推荐
政策利空对行情没有长期影响,牛市仍将继续 2021-05-19
[ROS](04)package.xml详解
2022-08-02日报:2022年7月最热的10篇AI论文
hsql是什么_MQL语言
[ROS] Compiling packages packages encounters slow progress or stuck, use swap
What is the difference between web testing and app testing?
shell脚本“画画”
Raft对比ZAB协议
MobileNet ShuffleNet & yolov5 replace backbone
[ROS](02)创建&编译ROS软件包Package
[ROS]ROS常用工具介绍(待续)
redis分布式锁和看门狗的实现
世界上最大的开源基金会 Apache 是如何运作的?
How to solve mysql service cannot start 1069
Unit 15 Paging, Filtering
replay视频播放器_怎么让手机音乐跟视频一起放
ftp常用命令详解_iftop命令详解
一维卷积神经网络_卷积神经网络的基础知识「建议收藏」
chapter7
What are the file encryption software?Keep your files safe