python - 获取错误 : django. core.exceptions.AppRegistryNotReady:在 django rest 框架中安装 oauth2 提供程序时尚未加载应用程序

标签 python django oauth-2.0

我正在尝试在 Django 中安装 django-oauth2-provider。安装和配置 settings.py 后,在迁移过程中,出现如下错误:

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

设置.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'hello_api',
    'rest_framework.authtoken',
    'provider',
    'provider.oauth2',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    #'corsheaders.middleware.CorsMiddleware',
]
ROOT_URLCONF = 'hello_api2.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

错误回溯:

error: File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/provider/oauth2/__init__.py", line 1, in <module>
    import backends
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/provider/oauth2/backends.py", line 2, in <module>
    from .forms import ClientAuthForm, PublicPasswordGrantForm
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/provider/oauth2/forms.py", line 10, in <module>
    from .models import Client, Grant, RefreshToken
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/provider/oauth2/models.py", line 23, in <module>
    class Client(models.Model):
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 105, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/home/ravi/PycharmProjects/hello-api2/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 237, in get_containing_app_config
    self.check_apps_ready()
  File "/home/ravi/PycharmProjects/hello-api2/venv/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-oauth2-provider 因为它不再被维护。最后一次更新是 3 年前。

您提供的追溯在他们针对 Django 1.9+ 的错误报告中。

https://github.com/caffeinehit/django-oauth2-provider/issues/136

但是您可以使用 Django OAuth Toolkit,它提供所有类似和增强的功能,并且还支持 Django >= 1.8。有关更多信息, read from here .

为了比较它们,你可以使用this source .

关于python - 获取错误 : django. core.exceptions.AppRegistryNotReady:在 django rest 框架中安装 oauth2 提供程序时尚未加载应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41390984/

相关文章:

python - Theano : MissingGxx , g++ 不可用

python - 如何使用计算过滤查询集?

iphone - iOS 从经过身份验证的 URL 流式传输音频

oauth-2.0 - 使用 OAuth2 在 Plone 站点上创建第三方 API?

android - 具有 Web View 的 native 移动应用程序的 SSO 方法?

python - tkinter 从动态复选框中获取值

python - Plotnine 中的错误栏

python - 为什么我得到 '_SIGCHLDWaker' object has no attribute 'doWrite' in Scrapy?

python - 根据列在DataFrame中插入值

Django 阻止页面缓存