2014-09-11 88 views
1

繼續我的搜索以獲得oauth2.0在pythonanywhere上的工作。django.core.exceptions.AppRegistryNotReady:模型尚未加載。 tastypie

我下面這個教程:http://ianalexandr.com/blog/building-a-true-oauth-20-api-with-django-and-tasty-pie.html

使用Django 1.6 IM:https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango

當我到了這行代碼:

from provider.oauth2.models import Client 
    # from django.contrib.auth.models import User 
    from django.contrib.auth import get_user_model 

    User = get_user_model() 
    u = User.objects.get(id=1) 
    c = Client(user=u, name="mysite client", client_type=1, url="http://pythonx00x.pythonanywhere.com") 
    c.save() 
    c.client_id 
    'd63f53a7a6cceba04db5' 
    c.client_secret 
    'afe899288b9ac4127d57f2f12ac5a49d839364dc' 

看來我在行得到一個錯誤:

User = get_user_model() 

它會產生一個錯誤:

raise AppRegistryNotReady("Models aren't loaded yet.") 
    django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. 

這裏是完整的堆棧跟蹤:

Traceback (most recent call last): 
    File "addClient.py", line 9, in <module> 
    User = get_user_model() 
    File "/home/python2006/.virtualenvs/django16/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 136, in get_user_model 
    return django_apps.get_model(settings.AUTH_USER_MODEL) 
    File "/home/python2006/.virtualenvs/django16/local/lib/python2.7/site-packages/django/apps/registry.py", line 200, in get_model 
    self.check_models_ready() 
    File "/home/python2006/.virtualenvs/django16/local/lib/python2.7/site-packages/django/apps/registry.py", line 132, in check_models_ready 
    raise AppRegistryNotReady("Models aren't loaded yet.") 
    django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. 

我似乎無法找出如何讓模型負荷。 如果我想到正確的想法。

回答

2

我想你可能不會使用你認爲你是的Django版本。 AppRegistryNotReady是在Django 1.7中引入的。我猜想,如果你將你的DJango版本固定爲1.6,你的代碼就可以工作。

+0

謝謝!我將嘗試使用:'code'pip install django == 1.6.1 – user3655850 2014-09-12 04:38:50

相關問題