我正在尝试从Django应用程序导入模型并收到错误:
ImportError at /
cannot import name UserProfile
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.3.1
Exception Type: ImportError
Exception Value:
cannot import name UserProfile
Exception Location: /Users/jonathan/pim/functions.py in <module>, line 2
Python Executable: /usr/local/bin/python
Python Version: 2.7.0
Python Path:
['/Users/jonathan/pim',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/distribute-0.6.14-py2.7.egg',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/pip-0.8.1-py2.7.egg',
'/usr/local/Cellar/python/2.7/lib/python27.zip',
'/usr/local/Cellar/python/2.7/lib/python2.7',
'/usr/local/Cellar/python/2.7/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/local/Cellar/python/2.7/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7/lib/python2.7/lib-old',
'/usr/local/Cellar/python/2.7/lib/python2.7/lib-dynload',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/PIL',
'/usr/local/lib/python2.7/site-packages',
'/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
Server time: Thu, 16 Feb 2012 12:14:07 -0600
Traceback Switch to copy-and-paste view
/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
request.path_info) ...
▶ Local vars
/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py in resolve
for pattern in self.url_patterns: ...
▶ Local vars
/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py in _get_url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) ...
▶ Local vars
/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py in _get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name) ...
▶ Local vars
/usr/local/Cellar/python/2.7/lib/python2.7/site-packages/django/utils/importlib.py in import_module
__import__(name) ...
▶ Local vars
/Users/jonathan/pim/../pim/urls.py in <module>
import pim_calendar.views ...
▶ Local vars
/Users/jonathan/pim/../pim/pim_calendar/views.py in <module>
import functions ...
▶ Local vars
/Users/jonathan/pim/functions.py in <module>
from pim_accounts import UserProfile ...
▶ Local vars
之前我遇到过类似的错误,我试图导入一个模型并被告知不可能发生。是否有反导入模型的规则?有没有另一种方法来实现同样的目标?该项目位于http://JonathansCorner.com/project/pim.tgz。
答案 0 :(得分:3)
在functions.py
中,更改行
from pim_accounts import UserProfile
到
from pim_accounts.models import UserProfile