0

更新:

我试过修改from actstream import settings as actstream_settingsimport actstream.settings as actstream_settings,它告诉我:

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

应用程序中的__init__.py文件actstream不是空的,这可能是它无法导入actstream/settings.py的原因actstream.settings吗?

原始问题:

我有一个工作 django 项目。我从主干安装了以下应用程序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 导入。

4

0 回答 0