我試圖在Django中安裝django-oauth2提供程序。遷移過程中安裝和配置settings.py,之後,我收到錯誤,如:獲取錯誤:django.core.exceptions.AppRegistryNotReady:在django rest框架中安裝oauth2提供程序時未裝載應用程序
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
settings.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年內還沒有更新,這就是可能導致問題的原因。繼續尋找一款滿足您需求的新套餐。 –