2016-05-11 16 views
0

Django 1.9プロジェクトでdjango-shopify-syncを使用しようとしています。アプリの設定を読み込むときに、設定でいくつかのモデルを読み込もうとしているので、次のエラーが表示されます。Django 1.9 django.core.exceptions.AppRegistryNotReady:アプリケーションはまだロードされていません

2つのインポートを移動して、最終的にモデルを次のready()関数にインポートしようとしましたが、引き続き同じエラーが発生しました。 https://github.com/andresdouglas/django-shopify-sync/blob/master/shopify_sync/apps.py

誤りがある次のファイルでCulpirt線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. 

UPDATE:私はhttps://github.com/andresdouglas/django-shopify-sync/blob/master/shopify_sync/handlers.py#L3-L4get_topic_models内部に次の行(モデル輸入)を移動した場合には、エラーを修正しているようです。しかし、それは一種の汚れです、誰かがより良い解決策を考え出すことができますか?

+0

確かに犯人のように見えますが、実証されるまでは無罪です。 ./manage.py runserverを実行するときにこのエラーが表示されるか、他のものと – e4c5

+0

@ e4c5サーバーを実行しているときは、yes – Andres

+0

INSTALLED_APPSのアプリとしてshopify-syncを登録しましたか? – e4c5

答えて

0

注文の問題があるようです。 django-shopify-syncの後にアプリケーションが INSTALLED_APPSタプルにあることを確認してください。 Application registry documentationに詳細があります。

インラインインポートが不満足なので、あなたはそれに悩まされているかもしれません。私はapps.pyready方法に

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

を移動することをお勧めしたいです。モデルの準備が整うまでインポートが遅れます。

私が試した変更は、次のとおりです。

diff --git a/shopify_sync/apps.py b/shopify_sync/apps.py 
index 663b43b..0bc1fcc 100644 
--- a/shopify_sync/apps.py 
+++ b/shopify_sync/apps.py 
@@ -1,7 +1,5 @@ 
from django.apps import AppConfig 
-from shopify_sync.handlers import webhook_received_handler 
-from shopify_webhook.signals import webhook_received 
- 
+import importlib 

class ShopifySyncConfig(AppConfig): 
    """ 
@@ -16,5 +14,9 @@ class ShopifySyncConfig(AppConfig): 
     The ready() method is called after Django setup. 
     """ 

+  signals_webhook_received = importlib.import_module('.signals', package='shopify_webhook') 
+  handlers_webhook_received_handler = importlib.import_module('.handlers', package='shopify_sync') 
+ 
     # Connect shopify_webhook's webhook_received signal to our synchronisation handler. 
-  webhook_received.connect(webhook_received_handler, dispatch_uid = 'shopify_sync_webhook_received_handler') 
+  signals_webhook_received.webhook_received.connect(handlers_webhook_received_handler.webhook_received_handler, dispatch_uid = 'shopify_sync_webhook_received_handler') 
+ 
+0

django-shopify-syncは、私が追加しようとしているアプリケーションです。どの他のアプリケーションを参照していますか? – Andres

+0

私の悪い、私はあなたの質問を誤解しました。 Lemmeはもう少し近く見える。 –

+0

@Andres:答えは現在適切であるはずです。 –

関連する問題