1

我想知道为什么我ImportError在使用django-cities时会得到一个。

from cities.models import PostalCode

我已经同步cities了数据库,并且数据库中存在表。追溯:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
   File "/lib/python2.7/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/lib/python2.7/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/lib/python2.7/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/lib/python2.7/django/core/management/__init__.py", line 69, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/lib/python2.7/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/lib/python2.7/South-0.7.5-py2.7.egg/south/management/commands/__init__.py", line 10, in <module>
    import django.template.loaders.app_directories
  File "/lib/python2.7/django/template/loaders/app_directories.py", line 23, in <module>
    raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
django.core.exceptions.ImproperlyConfigured: ImportError haystack: cannot import name PostalCode

ImportError 表明 python 正在寻找PostalCodein haystack,但我要求它从 . 导入cities。为什么会发生这种情况?谢谢你的想法!

4

2 回答 2

1

我解决了这个问题。尽管 github 和 pypi 版本都声称是 0.2,但事实证明它们是不同的。我是通过 pip 安装的,pypi 版本没有PostalCode模型类,这是我的ImportError. 谢谢!

于 2013-01-31T01:22:57.307 回答
0

问题更有可能出在您的models.py 中。您可以进行循环导入(换句话说,A 从 B 导入和 B 从 A 导入的情况)。

于 2013-01-30T23:14:37.013 回答