Django,request.user始终是匿名用户 [英] Django, request.user is always Anonymous User

查看:165
本文介绍了Django,request.user始终是匿名用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用针对Django的自定义身份验证后端(运行在ouchdb上)。我有一个自定义的用户模型。

I am using a custom authentication backend for Django (which runs off couchdb). I have a custom user model.

作为登录的一部分,我正在执行 request.user = user 并在会话中保存用户ID。
但是,在后续请求中,我无法检索到request.user。它始终是AnonymousUser。但是,我可以从会话中检索用户ID,并可以确认会话cookie设置正确。

As part of the login, I am doing a request.user = user and saving the user id in session. However, on subsequent requests, I am not able to retrieve the request.user. It is always an AnonymousUser. I can, however, retrieve the user id from the session and can confirm that the session cookie is being set correctly.

我丢失了什么?

我不想使用关系数据库,因为我想将我的所有用户数据都保存在beddb中。

I do not want to use a relational db as I want to maintain all my user data in couchdb.

编辑:我编写了一个不从Django的auth User继承的类。但是,它具有用户名和电子邮件属性。因此,我的后端没有返回派生自auth User的类。

Edit: I have written a class which does not inherit from Django's auth User. It, however, has the username and email attributes. For this reason, my backend does not return a class which derives from auth User.

推荐答案

请详细说明。如果您使用的是自定义用户模型(与自定义用户PROFILE模型不同),则您基本上是一个人,并且django.contrib.auth框架无法帮助您进行身份验证。如果您正在编写自己的身份验证系统而不使用django.contrib.auth,则需要将其关闭,因为它似乎干扰了您的系统。

Please elaborate. If you are using a custom user model (which is different from a custom user PROFILE model), then you are basically on your own and the django.contrib.auth framework can not help you with authentication. If you are writing your own authentication system and are not using django.contrib.auth, then you need to turn that off because it seem to be interfering with your system.

这篇关于Django,request.user始终是匿名用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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