Django 1.3 版本包括 RemoteUserMiddleware
和
RemoteUserBackend
类允许 Apache 进行身份验证。
参见 http://docs.djangoproject.com/en/dev/howto/auth-remote-user/
我有一个 initial_data.json,它在执行 syncdb 时创建一个 super 用户。转储数据证实了这一点。
但我发现它似乎无法使用新创建的数据库正确登录。我收到一个 ImproperlyConfigured 异常,上面写着: Django远程用户认证中间件需要安装认证中间件。
Edit your MIDDLEWARE_CLASSES setting to insert django.contrib.auth.middleware.AuthenticationMiddleware' before the RemoteUserMiddleware class.
回溯指向RemoteMilddleware.process_request()
:
def process_request(self, request):
# AuthenticationMiddleware is required so that request.user exists.
if not hasattr(request, 'user'):
raise ImproperlyConfigured(...
Apache 的 DEBUG 输出显示设置实际上有 AuthenticationMiddleware
和 RemoteUserMiddleware
按照请求的顺序:
MIDDLEWARE_CLASSES
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
但是没有设置request.user属性,产生了异常。
如果我仔细查看 django.contrib.auth.backends 和中间件的源代码,
我发现 AuthenticationMiddleware
正在为 LazyUser
注册
请求类。但是RemoteUserBackend
好像没有
调用的 authenticate() 方法是在 Users 表中查找 remote_user 的地方。
我应该做些什么来调用 authenticate()
以创建 request.user?
我可以根据需要提供更多信息。顺便说一下,这是使用 SSL。这是否有一些我没有预料到的互动?
我应该提到我正在使用 Apache2.2.14 和 mod_wsgi
。
最佳答案
我遇到了同样的问题,经过一些调试后发现我忘记为 auth 和其他应用程序创建 mysql(我认为它与 sqllite 的情况相同)表。因此,如果您不这样做,则需要运行 python manage.py syncdb 或以其他方式创建它们
关于python - 使用新数据库帮助 Django RemoteUserMiddleware RemoteUserBackend,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5877686/