模块"mymodule"没有定义"MyBackend"身份验证后端

Zac*_*man 2 python authentication django

我正在尝试为我正在使用的Django项目使用自定义身份验证后端.我的后端基于在带有后端的Django中的LDAP身份验证一文中找到的LDAPBackend .

当我尝试登录时,我收到了floowing错误:

ImproperlyConfigured at /admin/ 
Module "challenge.backends" does not define a "LDAPBackend" authentication backend
Run Code Online (Sandbox Code Playgroud)

我的项目被称为"挑战".有一个子目录,"后端",其中包含__init__.pyLDAPBackend.py.

settings.py的配置是这样使用这个后端:

AUTHENTICATION_BACKENDS = (
    'challenge.backends.LDAPBackend',
    'django.contrib.auth.backends.ModelBackend',
)
Run Code Online (Sandbox Code Playgroud)

我可以自己导入模块python manage.py shell然后使用from challenge.backends import LDAPBackend.

我不知道现在要检查什么,因为一切似乎都在正确的地方.

gru*_*czy 6

你是以错误的方式导入它.您正在导入模块,而不是类.这就是为什么shell允许你导入它,但django抱怨.

你应该用challenge.backends.LDAPBackend.LDAPBackend.

此外,在命名模块时坚持使用PEP8是个好主意,这样你就不会再这样混淆了.模块应该是小写的名称,没有空格,下划线等.