当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
idea社区版下载安装教程_安装天然气管道的流程
Why does a four-byte float represent a wider range than an eight-byte long
Basic operations of 8583 sequential stack
期货具体是如何开户的?
【ROS】编译软件包packages遇到进度缓慢或卡死,使用swap
Sentinel源码(三)slot解析
drf序列化器-Serializer
drf视图组件
你接受不了60%的暴跌,就没有资格获得6000%的涨幅 2021-05-27
Flask框架的搭建及入门
FFmpeg 的AVCodecContext结构体详解
Chapter6 visualization (don't want to see the version)
Go语言初始
[ROS](03)CMakeLists.txt详解
网络安全第四次作业
hsql是什么_MQL语言
世界上最大的开源基金会 Apache 是如何运作的?
Sentinel源码(六)ParamFlowSlot热点参数限流
The bad policy has no long-term impact on the market, and the bull market will continue 2021-05-19
RowBounds[通俗易懂]









