2016-12-30 85 views
4

我試圖在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. 
+0

不要使用'django-oauth2-provider',它在3年內還沒有更新,這就是可能導致問題的原因。繼續尋找一款滿足您需求的新套餐。 –

回答

2

你不應該使用django-oauth2-provider,因爲它不再被維護。最近一次更新是3年前。

你提供的回溯在Django 1.9+的bug報告中。

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

但是可以使用的Django OAuth的工具包,其提供所有的類似和增強的功能,同時還支持的Django> = 1.8.For的更多信息, read from here。可以使用this source

+0

謝謝..我幫助.. :) – Ravi

+0

我很高興聽到和抱歉,我不知道一個好的項目建議。 –

+0

如果遇到一個或一個人,我會更新我的答案。 –