Django Models Multifile导致django.contrib错误

时间:2017-02-05 15:09:41

标签: python django

我正在研究Django项目,我遇到了使用多文件模型导入django.contrib的问题。

我的环境是使用Django 1.10.5的Python 2.7 VirtualEnv

这是堆栈跟踪:

    Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/vbrice/Projects/Pro/labs/Puffin/app/__init__.py", line 1, in <module>
    import views
  File "/Users/vbrice/Projects/Pro/labs/Puffin/app/views/__init__.py", line 3, in <module>
    from login import login_view
  File "/Users/vbrice/Projects/Pro/labs/Puffin/app/views/login.py", line 4, in <module>
    import models
  File "/Users/vbrice/Projects/Pro/labs/Puffin/models/__init__.py", line 1, in <module>
    from .category import Category
  File "/Users/vbrice/Projects/Pro/labs/Puffin/models/category.py", line 3, in <module>
    from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
  File "/usr/local/lib/python2.7/site-packages/django/contrib/contenttypes/fields.py", line 5, in <module>
    from django.contrib.contenttypes.models import ContentType
  File "/usr/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 138, in <module>
    class ContentType(models.Model):
  File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 105, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 237, in get_containing_app_config
    self.check_apps_ready()
  File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

我无法弄清楚为什么我可以访问django.db而不是django.contrib.authdjango.contrib.contenttypes

以下是我安装的应用:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'oauth2_provider',
    'app',
    'api',
]

有没有人遇到同样的问题?

0 个答案:

没有答案