django 会话密钥在身份验证时更改 [英] django session key changing upon authentication

查看:22
本文介绍了django 会话密钥在身份验证时更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 存储匿名用户数据

但是,会话密钥似乎在用户登录/注册时发生了变化,因此会话密钥无法再与用户关联.这是 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'

在文件 session_backend.py 中的目录 youapp

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆