从backend.get_user访问的request.session [英] Access request.session from backend.get_user

查看:196
本文介绍了从backend.get_user访问的request.session的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先:这是的的一样这个。该ModelBackend没有要求成员。

first of all: this is not the same as this. The ModelBackend has no request member.

我想没有进入全球请求对象或他/她的会话ID访问当前用户的会话。

I want to access the session of the current user without access to the global request object or his/her session ID.

为什么呢?我写我自己的认证后端,延长 ModelBackend 。在我所具备的功能 GET_USER(个体经营,USER_ID),即得到每个请求叫(这是由Django的权威性中间件自动完成)。不幸的是, GET_USER 没有获得要求,但仍然在我的情况下,我想检查与数据会话(又为什么呢?因为我没有本地数据库,并从远程中间件的所有数据。该会议将是做一些类型的缓存一个舒适的方式)。

Why? I wrote my own authentication backend, extending ModelBackend. In that I have the function get_user (self, user_id), that gets called with every request (this is done automatically by the Django auth middleware). Unfortunately, get_user doesn't have access to request, but nonetheless in my case I want to check with data in the session (Why again? Because I don't have a local database and get all data from a remote middleware. The session would be a comfortable way to do some kind of caching).

推荐答案

RemoteUserBackend (从的 django.contrib.auth.backends )使用特殊中间件, RemoteUserMiddleware ,访问请求数据。也许你可以这样来做了。

The RemoteUserBackend (from django.contrib.auth.backends) uses special middleware, RemoteUserMiddleware, to access request data. Maybe you could do it this way, too.

这篇关于从backend.get_user访问的request.session的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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