【发布时间】:2016-05-11 00:28:25
【问题描述】:
尝试在 Django 1.9 项目中使用 django-shopify-sync。加载应用程序的配置时,它给了我以下错误,可能是因为它试图在配置中加载一些模型?
尝试将最终导入模型的两个导入移动到下面的 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 移动到 get_topic_models 内部,它似乎可以修复错误。但这有点脏,谁能想出更好的解决方案?
【问题讨论】:
-
这看起来确实是罪魁祸首,但在得到证实之前是无罪的。当您执行 ./manage.py runserver 或其他操作时,您是否看到此错误
-
@e4c5 运行服务器时,是的
-
您已将 shopify-sync 注册为 INSTALLED_APPS 中的应用程序?
-
正确。当我删除它时,它不会发生
-
你能发布完整的回溯吗?
标签: python django shopify django-1.9