当前位置:网站首页>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 .
边栏推荐
- 数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)
- Soft test software designer full truth simulation question (including answer analysis)
- 独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
- Determine whether the linked list is a palindrome linked list
- 美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告
- How wild are hackers' ways of making money? CTF reverse entry Guide
- 剑指 Offer II 015. 字符串中的所有变位词
- 阿里云、追一科技抢滩对话式AI
- China benzene hydrogenation Market Research and investment forecast report (2022 Edition)
- PR basic clip operation / video export operation
猜你喜欢

How to cancel automatic search and install device drivers for laptops

Hi Fun Summer, play SQL planner with starrocks!

VMware 虛擬機啟動時出現故障:VMware Workstation 與 Hyper-v 不兼容...

Leetcode 77 combination -- backtracking method

Stegano in the world of attack and defense

如何写出好代码 — 防御式编程指南

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

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

SQL question brushing 627 Change gender

Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
随机推荐
6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
单例模式的懒汉模式跟恶汉模式的区别
Zabbix2.2 monitoring system and application log monitoring alarm
China sorbitol Market Forecast and investment strategy report (2022 Edition)
ShenYu 网关开发:在本地启用运行
美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告
独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
[C language supplement] judge which day tomorrow is (tomorrow's date)
String class
Hidden Markov model (HMM): model parameter estimation
String类
What are the differences between PHP and DW
Défaillance lors du démarrage de la machine virtuelle VMware: le poste de travail VMware n'est pas compatible avec hyper - V...
软件工程导论——第六章——详细设计
【C补充】【字符串】按日期排序显示一个月的日程
C language input / output stream and file operation
Soft test network engineer full truth simulation question (including answer and analysis)
数据库系统原理与应用教程(002)—— MySQL 安装与配置:MySQL 软件的卸载(windows 环境)
Tutorial on the principle and application of database system (001) -- MySQL installation and configuration: installation of MySQL software (Windows Environment)
redis -- 数据类型及操作