Django + Testypie Проблема: AppRegistryNotReadyException - PullRequest
0 голосов
/ 31 октября 2018

Я пробовал Testipie с Django и получил исключение AppRegistryNotReady. Я нашел несколько способов как это исправить, но ничего не помогло.

  • Python: 3,6
  • Джанго: 2.1.2
  • Джанго-лакомство: 0,14,2

Установленные приложения



    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'services',
        'tastypie'
    ]

услуги / __ __ INIT. Ру

`default_app_config = 'services.apps.ServicesConfig'`

услуги / apps.py



    from django.apps import AppConfig
    from django.contrib.auth import get_user_model
    from django.db.models import signals
    from tastypie.models import create_api_key
    User = get_user_model()
    class ServicesConfig(AppConfig):
        name = 'services'
        def ready(self):
            signals.post_save.connect(create_api_key, sender=User)

И я получил трассировку:



    Traceback (most recent call last):
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
        fn(*args, **kwargs)
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
        autoreload.raise_last_exception()
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception
        raise _exception[1]
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
        autoreload.check_errors(django.setup)()
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
        fn(*args, **kwargs)
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
        app_config = AppConfig.create(entry)
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/apps/config.py", line 116, in create
        mod = import_module(mod_path)
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "", line 994, in _gcd_import
      File "", line 971, in _find_and_load
      File "", line 955, in _find_and_load_unlocked
      File "", line 665, in _load_unlocked
      File "", line 678, in exec_module
      File "", line 219, in _call_with_frames_removed
      File "/home/chumachenko/Documents/Projects/tastypie_tutorial/services/apps.py", line 4, in 
        from tastypie.models import create_api_key
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/tastypie/models.py", line 15, in 
        class ApiAccess(models.Model):
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/db/models/base.py", line 87, in __new__
        app_config = apps.get_containing_app_config(module)
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/apps/registry.py", line 249, in get_containing_app_config
        self.check_apps_ready()
      File "/home/chumachenko/.local/share/virtualenvs/tastypie_tutorial-aq48eQFJ/lib/python3.6/site-packages/django/apps/registry.py", line 132, in check_apps_ready
        raise AppRegistryNotReady("Apps aren't loaded yet.")
    django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

Может, у кого-то уже была такая проблема?

Ответы [ 2 ]

0 голосов
/ 01 ноября 2018

Я нашел решение этой проблемы. Вы должны внести несколько изменений в services / apps.py



    from django.apps import AppConfig
    from django.contrib.auth import get_user_model
    from django.db.models import signals


    class ServicesConfig(AppConfig):
        name = 'services'

        # This line dispatches signal to Tastypie to create APIKey
        def ready(self):
            from tastypie.models import create_api_key
            User = get_user_model()
            signals.post_save.connect(create_api_key, sender=User)

0 голосов
/ 01 ноября 2018

Попробуйте заменить `` default_app_config = 'services.apps.ServicesConfig' на default_app_config = 'services.apps.AppConfig'

...