django 运行报错:django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

问题简述:

       使用自定义认证,增加一个class MyUserBackend(ModelBackend),并在setting中AUTHENTICATION_BACKENDS设置为MyUserBackend。

运行后一直报错:

File "E:\work\广东机电\ldap_test1\ldap_ck\apps.py", line 2, in 
    from django.contrib.auth.backends import ModelBackend
  File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\auth\backends.py", line 4, in 
    from django.contrib.auth.models import Permission
  File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\auth\models.py", line 4, in 
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "D:\ProgramData\Anaconda3\lib\site-packages\django\contrib\auth\base_user.py", line 52, in 
    class AbstractBaseUser(models.Model):
  File "D:\ProgramData\Anaconda3\lib\site-packages\django\db\models\base.py", line 110, in __new__
    app_config = apps.get_containing_app_config(module)
  File "D:\ProgramData\Anaconda3\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
    self.check_apps_ready()
  File "D:\ProgramData\Anaconda3\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

    后发现当MyUserBackend放在apps.py中就会出现此问题,而放在views.py中就不会有此问题。

 解决方法:

    将MyUserBackend定义在views.py中。


你可能感兴趣的:(python)