当前位置:网站首页>Cookies and session keeping technology
Cookies and session keeping technology
2022-07-01 16:56:00 【Legal procedures for working in banks】
conversation : The browser visits the website until the end of the visit is a session
HTTP Protocol is stateless .cookies and session Two storage technologies to solve the stateless problem .
1.cookies
Is the storage space saved on the client browser
Store in the form of key value pairs on the browser , Stored data has a lifecycle , Secure domain storage isolation , Cannot access between different domains . At every request , The browser will carry cookies To the server .
1.1 cookies Use
HttpResponse.set_cookie(key,value='',max_age=None,expires=None)
- key cookie Name
- value cookie Value
- max_age Survival time , second
- expires Specific expiration time
- When not formulated max_age perhaps expires when , When the browser is closed, it will fail
# Set up cookies
def set_cookies(request):
resp = HttpResponse('set cookies is ok')
resp.set_cookie('uuname','nicos',500)
return resp
# obtain cookies
def get_cookies(request):
resp = request.COOKIES.get('uuname','null')
return HttpResponse('cookie is :%s'%(resp))
# Delete cookies
def del_cookies(request):
resp = HttpResponse(' Delete COOKIES')
resp.delete_cookie('uuname')
return resp

2. session
The space on the server is used to store important data of browser server interaction , Use session You must first enable cookie, And cookie Storage in sessionid, Each client can have an independent session, Requestors are independent .sessionid Because saved in cookies, So the life cycle is the same as him
Use sessionn, Check settings.py Whether to add
INSTALLED_APPS = [
’django.contrib.sessions’,
MIDDLEWARE = [
’django.contrib.sessions.middleware.SessionMiddleware’,
def set_session(request):
request.session['uuname']='wwwwww'
return HttpResponse('set session is ok')
def get_session(request):
value = request.session['uuname']
return HttpResponse(value)
settings.py Related configuration items in
1.session_cookie_age: Appoint sessionid stay cookies Length of time saved in , The default is 2 Zhou .
2.session_expire_at_borwser_close=True If you close the browser, it won't work
3.Django Medium session Data stored in database , So use session sign , Need to ensure that migrate.
4.session It is a continuous single table involving , And change the data for two continuous holdings
5. Can be performed every night python manage.py clearsessions, This command deletes expired session data .
边栏推荐
- China nylon 11 industry research and future forecast report (2022 Edition)
- How does go use symmetric encryption?
- China sorbitol Market Forecast and investment strategy report (2022 Edition)
- ACL 2022 | 分解的元学习小样本命名实体识别
- Determine whether the linked list is a palindrome linked list
- sql刷题584. 寻找用户推荐人
- 判断二叉树是否为二叉搜索树
- 博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
- Rhcsa Road
- ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
猜你喜欢

Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!

模板引擎Velocity 基礎

How to restore the system with one click on Lenovo laptop

重磅披露!上百个重要信息系统被入侵,主机成为重点攻击目标

Pytest learning notes (13) -allure of allure Description () and @allure title()

C language input / output stream and file operation

阿里云、追一科技抢滩对话式AI

VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v

Défaillance lors du démarrage de la machine virtuelle VMware: le poste de travail VMware n'est pas compatible avec hyper - V...

Tutorial on the principle and application of database system (003) -- MySQL installation and configuration: manually configure MySQL (Windows Environment)
随机推荐
Leetcode 77 combination -- backtracking method
Virtual serial port simulator and serial port debugging assistant tutorial "suggestions collection"
Is it reliable to open an account on flush with mobile phones? Is there any potential safety hazard
Kali install Nessus
Leetcode 216 combined summation III -- backtracking method
Girls who want to do software testing look here
What are the differences between PHP and DW
mysql -- explain性能优化
Redis Distributed Lock
[kotlin] Introduction to higher-order functions
SQL注入漏洞(Mysql与MSSQL特性)
Free lottery | explore the future series of blind box digital copyright works of "abadou" will be launched on the whole network!
How to repair the laptop that cannot connect to the wireless network
智能运维实战:银行业务流程及单笔交易追踪
Bugku's file contains
Redis 分布式鎖
How to optimize repeated if err in go language= Nil template code?
模板引擎Velocity 基础
How to restore the system of Sony laptop
[Supplément linguistique c] déterminer quel jour est demain (date de demain)