Почему я не могу импортировать модель Django из другого исходного файла? - PullRequest
1 голос
/ 16 февраля 2012

Я пытаюсь импортировать модель из приложения 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.

1 Ответ

3 голосов
/ 16 февраля 2012

В functions.py, изменить строку

from pim_accounts import UserProfile

до

from pim_accounts.models import UserProfile
...