django会话密钥在认证时更改 [英] django session key changing upon authentication
问题描述
我有一个Django应用程序,用于记录用户的身份验证用户的产品选择。我的意图是使用 request.session.session_key
变量将匿名数据与用户关联,如果他们决定稍后注册,那么这个帖子:
I have a Django app which records users' product choices for both authenticated users. My intention is to use the request.session.session_key
variable to associate anonymous data with a user if they decide to register later, a la this post:
但是,当用户登录/注册时,似乎会话密钥更改,因此会话密钥不能再与用户关联。这是Django会话框架的正确行为。有没有实际的方法来实现我正在寻找的功能?
However, it seems that the session key changes when the user logs in/ registers so the session key can no longer be associated with the user. Is this the correct behaviour of the Django session framework. Is there a solid way to achieve the functionality I'm looking for?
任何帮助非常感谢。
推荐答案
在settings.py
In settings.py
SESSION_ENGINE ='youapp.session_backend'
SESSION_ENGINE = 'youapp.session_backend'
在目录youapp中的文件session_backend.py
in directory youapp in file session_backend.py
from django.contrib.sessions.backends.db import SessionStore as DbSessionStore
class SessionStore(DbSessionStore):
def cycle_key(self):
pass
登录后会话未更改
这篇关于django会话密钥在认证时更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!