标签:配置 pass res 技术 soc code 设置redis url settings
1.安装包
pip install redis pip install django-redis-sessions
2.settings.py 配置
# 添加配置信息 # 设置redis存储session信息 SESSION_ENGINE = ‘redis_sessions.session‘ SESSION_REDIS = { ‘host‘: ‘127.0.0.1‘, # 地址 ‘port‘: 6379, # 端口号 ‘db‘: 2, # 数据库 ‘password‘: ‘‘, # 密码 ‘prefix‘: ‘session‘, # 标识符 ‘socket_timeout‘: 10 # 超时时间 }
3.views.py
# 存入数据 def set_session(request): request.session[‘username‘] = ‘qqqqqqq‘ request.session[‘age‘] = ‘18‘ return HttpResponse(‘设置session‘) # 读取数据 def get_session(request): username = request.session[‘username‘] age = request.session[‘age‘] return HttpResponse(username+‘:‘+str(age))
4.urls.py
path(‘set_session‘, views.set_session), path(‘get_session‘, views.get_session),
5.redis-cli
标签:配置 pass res 技术 soc code 设置redis url settings
原文地址:https://www.cnblogs.com/wangdianchao/p/13202648.html