使用自定义身份验证后端为自定义用户模型启用Django Admin

时间:2013-09-05 06:27:14

标签: django django-admin

我有一个自定义用户模型,我自己的身份验证到位。但尽管如此,我无法登录Django管理员。页面出现但它不接受我的凭据(这是正确的)。我在django.contrib.auth.backends.ModelBackend中添加了AUTHENTICATION_BACKENDS以及我的自定义身份验证后端。我在签入shell时都设置了is_staffis_admin

我错过了一些明显的东西吗?

AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend',
                            'final.backends.CustomBackend',)


AUTH_USER_MODEL = 'final.MyUser'

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)


INSTALLED_APPS = (
'rest_framework.authtoken',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'final',
'rest_framework',
)

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
    'final.authentication.ExpiringTokenAuthentication',
)
}

请忽略糟糕的压痕。他们迷失在复制粘贴大屠杀中。

0 个答案:

没有答案