1,安装django-redis-session0.6
pip install django-redis-session==0.6
2,编辑settings.py文件
SESSION_ENGINE = 'redis_sessions.session'
SESSION_REDIS = {
'host': 'localhost',
'port': 6379,
'db': 0,
'password': '',
'prefix': 'session',
'socket_timeout': 1
}
3,views.py中使用
request.session['user_name']='user_name' # 设置session
request.session.get('user_name') # 取出session
del request.session['user_name'] # 删除session