Django get_model()导致错误:无法导入名称设置

时间:2012-07-26 15:51:02

标签: django import settings importerror

更新

我已尝试将from actstream import settings as actstream_settings修改为import actstream.settings as actstream_settings并告诉我:

AttributeError: 'module' object has no attribute 'settings'

__init__.py应用中的actstream文件不为空,这可能导致无法将actstream/settings.py导入为actstream.settings吗?

原始问题:

我有一个工作的django项目。我从trunk安装了以下应用actstream,因为最新版本有错误:https://github.com/justquick/django-activity-stream

将此应用程序加载到我的项目中时会抛出以下异常:

Error: cannot import name settings

我已经验证错误来自get_model()的第一个命令actstream/settings.py,如下所示:

from django.conf import settings
from django.db.models import get_model
import sys

MODELS = {}
for model in getattr(settings, 'ACTSTREAM_ACTION_MODELS', ('auth.User',)):
    MODELS[model.lower()] = model = get_model(*model.split('.'))

MANAGER_MODULE = getattr(settings, 'ACTSTREAM_MANAGER',
    'actstream.managers.ActionManager')
a, j = MANAGER_MODULE.split('.'), lambda l: '.'.join(l)
MANAGER_MODULE = getattr(__import__(j(a[:-1]), {}, {}, [a[-1]]), a[-1])

USE_JSONFIELD = getattr(settings, 'ACTSTREAM_USE_JSONFIELD', False)

为什么get_model()会因为无法在此实例中加载settings而引发错误?

回溯:

Traceback (most recent call last):
  File ".../actstream/settings.py", line 7, in <module>
    MODELS[model.lower()] = model = get_model(*model.split('.'))
  File ".../lib/python2.7/site-packages/django/db/models/loading.py", line 213, in get_model
    self._populate()
  File ".../lib/python2.7/site-packages/django/db/models/loading.py", line 67, in _populate
    self.load_app(app_name)
  File ".../lib/python2.7/site-packages/django/db/models/loading.py", line 88, in load_app
    models = import_module('.models', app_name)
  File ".../lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File ".../libs/actstream/models.py", line 12, in <module>
    from actstream import managers, settings as actstream_settings
ImportError: cannot import name settings

我现在注意到导入错误发生在models.py中,但我仍然看不到它如何无法将settings.py文件导入为actstream.settings。

0 个答案:

没有答案