当我尝试从django.contrib.auth.models或django的任何其他模型类导入User时,我总是遇到相同的错误。 我安装了Python 3.7,制作了新的virtualenv,这是对错误的完整追溯:
(trytest) C:\Users\User\Desktop\trytest\Scripts\trytest>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.contrib.auth.models import User
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Marin\Desktop\trytest\lib\site-
packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser,
BaseUserManager
File "C:\Users\Marin\Desktop\trytest\lib\site-
packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\Marin\Desktop\trytest\lib\site-
packages\django\db\models\base.py", line 100, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Users\Marin\Desktop\trytest\lib\site-
packages\django\apps\registry.py", line 244, in get_containing_app_config
self.check_apps_ready()
File "C:\Users\Marin\Desktop\trytest\lib\site-
packages\django\apps\registry.py", line 127, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
这只是我安装的测试项目,以查看我是否会在全新安装中遇到相同的问题。 Virtualenv已激活。 是Python还是Django的问题,我在网上找不到有用的东西。