继续寻找答案,让oauth2.0在pythonanywhere上运行。
我正在关注本教程:http://ianalexandr.com/blog/building-a-true-oauth-20-api-with-django-and-tasty-pie.html
即时使用django 1.6: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.
我似乎无法找到如何让模型加载。 如果我的想法是对的。
答案 0 :(得分:2)
我认为您可能没有使用您认为自己的Django版本。 AppRegistryNotReady是在Django 1.7中引入的。我猜想,如果你将你的DJango版本固定为1.6,你的代码就可以了。