迪亚戈1.9Django.core.exceptions.AppRegistryNotReady:应用未加载y

2024-06-28 19:30:09 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试在django1.9项目中使用djangoshopify同步。当加载应用程序的配置时,它会给我以下错误,可能是因为它试图在配置中加载一些模型?在

尝试将最终导入模型的两个导入移到下面的ready()函数中,但仍然得到相同的错误。在下面的文件https://github.com/andresdouglas/django-shopify-sync/blob/master/shopify_sync/apps.py中的第2行和第3行出错

错误是:

    $ python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x10753e500>
Traceback (most recent call last):
  File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/config.py", line 116, in create
    mod = import_module(mod_path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/apps.py", line 2, in <module>
    from shopify_sync.handlers import webhook_received_handler
  File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/handlers.py", line 3, in <module>
    from .models import (CustomCollection, Customer, Order, Product, Shop,
  File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/models/__init__.py", line 3, in <module>
    from .address import Address
  File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/models/address.py", line 6, in <module>
    from .base import ShopifyResourceModel
  File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/models/base.py", line 144, in <module>
    class ShopifyResourceModel(models.Model):
  File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/db/models/base.py", line 94, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
    self.check_apps_ready()
  File "/Users/andres/.virtualenvs/[...]/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.

更新:如果我将以下行(模型导入)https://github.com/andresdouglas/django-shopify-sync/blob/master/shopify_sync/handlers.py#L3-L4移到insideget_topic_models中,似乎可以修复错误。但这有点肮脏,有人能想出更好的解决方案吗?在


Tags: appsdjangoinpylibpackageslinesite
2条回答

如果移动以下行(模型导入)https://github.com/andresdouglas/django-shopify-sync/blob/master/shopify_sync/handlers.py#L3-L4

from .models import (CustomCollection, Customer, Order, Product, Shop,
                 SmartCollection)

get_topic_models中,它似乎修复了错误。但这有点肮脏,有人能想出更好的解决方案吗?在

你好像有订货问题。请确保您的应用程序位于INSTALLED_APPS元组中django-shopify-sync之后。您可以在Application registry documentation中找到更多详细信息。

正如内联导入不令人满意一样,您可能会被它卡住。我建议搬家

from shopify_sync.handlers import webhook_received_handler
from shopify_webhook.signals import webhook_received

apps.py中的ready方法中。这将延迟导入,直到模型准备就绪。在

我尝试的改变是:

^{pr2}$

相关问题 更多 >