在我的django 1.6
个应用SOME_APP
之一中,我尝试连接tastypie
信号,以便在User
创建时生成API密钥,如tastypie
文档:
http://django-tastypie.readthedocs.org/en/latest/authentication.html
在MY_SITE/SOME_APP/signals.py
我有:
from django.contrib.auth.models import User
from django.db import models
from tastypie.models import create_api_key
models.signals.post_save.connect(create_api_key, sender=User)
并在MY_SITE/SOME_APP/__init__.py
我有:
from . import signals
当我尝试运行我的开发服务器时,我得到以下回溯:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/USER/git/MY_SITE/SOME_APP/__init__.py", line 5, in <module>
from . import signals
File "/home/USER/git/MY_SITE/SOME_APP/signals.py", line 12, in <module>
from tastypie.models import create_api_key
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/tastypie/models.py", line 32, in <module>
from tastypie.compat import AUTH_USER_MODEL
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/tastypie/compat.py", line 14, in <module>
User = get_user_model()
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 127, in get_user_model
user_model = get_model(app_label, model_name)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/db/models/loading.py", line 271, in get_model
self._populate()
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/debug_toolbar/models.py", line 63, in <module>
patch_root_urlconf()
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/debug_toolbar/models.py", line 51, in patch_root_urlconf
reverse('djdt:render_panel')
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 480, in reverse
app_list = resolver.app_dict[ns]
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 310, in app_dict
self._populate()
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 262, in _populate
for pattern in reversed(self.url_patterns):
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 346, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 341, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/USER/git/MY_SITE/MY_SITE/urls.py", line 13, in <module>
from SOME_APP.api.resources import PostResource #for tastypie REST API access
File "/home/USER/git/MY_SITE/SOME_APP/api/resources.py", line 6, in <module>
from tastypie.resources import ModelResource
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/tastypie/resources.py", line 19, in <module>
from tastypie.authentication import Authentication
File "/home/USER/.virtualenvs/virt-develop/local/lib/python2.7/site-packages/tastypie/authentication.py", line 14, in <module>
from tastypie.compat import User, username_field
ImportError: cannot import name User
导致此错误的原因是什么?如何解决?
感谢您的任何想法和建议:)