当前位置:网站首页>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 .
边栏推荐
- The difference between the lazy mode of singleton mode and the evil mode
- How wild are hackers' ways of making money? CTF reverse entry Guide
- 游戏行业安全选择游戏盾,效果怎么样?
- How to solve the problem that the battery icon of notebook computer does not display
- Computed property “xxx“ was assigned to but it has no setter.
- Template engine velocity Foundation
- SystemVerilog-结构体(二)
- ACL 2022 | 分解的元学习小样本命名实体识别
- How to cancel automatic search and install device drivers for laptops
- 数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)
猜你喜欢

Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?

为国产数据库添砖加瓦,StoneDB 一体化实时 HTAP 数据库正式开源!

巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...

National Security Agency (NSA) "sour Fox" vulnerability attack weapon platform technical analysis report

软件工程导论——第六章——详细设计

Are you still using charged document management tools? I have a better choice! Completely free

Hi Fun Summer, play SQL planner with starrocks!

Installation and use of sqoop

你还在用收费的文档管理工具?我这有更牛逼的选择!完全免费

String class
随机推荐
Tutorial on the principle and application of database system (001) -- MySQL installation and configuration: installation of MySQL software (Windows Environment)
sql刷题586. 订单最多的客户
Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
SQL question brushing 586 Customers with the most orders
嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
mysql -- explain性能优化
Template Engine Velocity Foundation
Tutorial on the principle and application of database system (005) -- Yum offline installation of MySQL 5.7 (Linux Environment)
重磅披露!上百个重要信息系统被入侵,主机成为重点攻击目标
How to cancel automatic search and install device drivers for laptops
Redis6.0 新功能
Judge whether a binary tree is a balanced binary tree
Rhcsa Road
The difference between the lazy mode of singleton mode and the evil mode
Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
Leetcode 216 combined summation III -- backtracking method
Rhcsa Road
How to solve the keyboard key failure of notebook computer
redis -- 数据类型及操作
How to maintain the laptop battery