【发布时间】:2014-02-11 20:23:09
【问题描述】:
我正在尝试在 Django 1.5 中使用多个身份验证后端。
我想将RemoteUserBackend 与自定义header 和标准ModelBackend 一起使用
似乎我可以完成其中一项工作,但不能同时完成。如果我尝试使用ModelBackend 登录,我会收到此错误:
"'CustomHeaderMiddleware' object has no attribute 'authenticate'"
settings.py:
MIDDLEWARE_CLASSES = (
...
'myapp.backends.custom_auth.CustomHeaderMiddleware',
...
)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'django.contrib.auth.backends.RemoteUserBackend',
'myapp.backends.custom_auth.CustomHeaderMiddleware',
)
custom_auth.py:
from django.contrib.auth.middleware import RemoteUserMiddleware
class CustomHeaderMiddleware(RemoteUserMiddleware):
header = "CUSTOM_USERID"
我不确定我错过了什么。如果我设置了“CUSTOM_USERID”,它可以工作,但我不能使用标准登录。
我错过了什么?
【问题讨论】:
-
为什么要在身份验证后端使用中间件?
-
谢谢@karthikr!就是这样。
标签: django custom-authentication remoteusermiddleware