Devstack:TypeError:__ init __()需要2个参数(给定1个)

时间:2014-12-17 13:56:37

标签: python django devstack

我在eclipse的devstack中运行视界时遇到此错误。可能是它的配置错误,但我无法解决它。请帮忙

 WARNING:root:No local_settings file found.
    Traceback (most recent call last):
      File "/home/stack/git/horizon/manage.py", line 23, in <module>
        execute_from_command_line(sys.argv)
      File "/usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg/django/core/management/__init__.py", line 338, in execute_from_command_line
        utility.execute()
      File "/usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg/django/core/management/__init__.py", line 303, in execute
        settings.INSTALLED_APPS
      File "/usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg/django/conf/__init__.py", line 48, in __getattr__
        self._setup(name)
      File "/usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg/django/conf/__init__.py", line 44, in _setup
        self._wrapped = Settings(settings_module)
      File "/usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg/django/conf/__init__.py", line 92, in __init__
        mod = importlib.import_module(self.SETTINGS_MODULE)
      File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
        __import__(name)
      File "/home/stack/git/horizon/openstack_dashboard/settings.py", line 339, in <module>
        from horizon.utils import secret_key
      File "/home/stack/git/horizon/horizon/__init__.py", line 27, in <module>
        from horizon.base import Dashboard  # noqa
      File "/home/stack/git/horizon/horizon/base.py", line 45, in <module>
        from horizon import loaders
      File "/home/stack/git/horizon/horizon/loaders.py", line 57, in <module>
        _loader = TemplateLoader()
      File "/usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg/django/template/loader.py", line 50, in __init__
        super(BaseLoader, self).__init__(*args, **kwargs)
    TypeError: __init__() takes exactly 2 arguments (1 given)

Django加载程序文件在运行视界时显示错误。它在参数

中显示了类型错误
import warnings

from django.utils.deprecation import RemovedInDjango20Warning

from .base import Origin
from .engine import Engine


class LoaderOrigin(Origin):
    def __init__(self, display_name, loader, name, dirs):
        super(LoaderOrigin, self).__init__(display_name)
        self.loader, self.loadname, self.dirs = loader, name, dirs

    def reload(self):
        return self.loader(self.loadname, self.dirs)[0]


def find_template(*args, **kwargs):
    return Engine.get_default().find_template(*args, **kwargs)


def get_template(*args, **kwargs):
    return Engine.get_default().get_template(*args, **kwargs)


def get_template_from_string(*args, **kwargs):
    return Engine.get_default().get_template_from_string(*args, **kwargs)


def render_to_string(*args, **kwargs):
    return Engine.get_default().render_to_string(*args, **kwargs)


def select_template(*args, **kwargs):
    return Engine.get_default().select_template(*args, **kwargs)


# This line must remain at the bottom to avoid import loops.
from .loaders import base


class BaseLoader(base.Loader):
    _accepts_engine_in_init = False

    def __init__(self, *args, **kwargs):
        warnings.warn(
            "django.template.loader.BaseLoader was superseded by "
            "django.template.loaders.base.Loader.",
            RemovedInDjango20Warning, stacklevel=2)
        super(BaseLoader, self).__init__(*args, **kwargs)

2 个答案:

答案 0 :(得分:0)

Horizo​​n需要Django>=1.4.2,<1.7,您在此处使用Django 1.8(请参阅requirements.txt

__init__的{​​{1}}个参数在这两个版本之间发生了变化。

如果您希望这样做,您需要修复您的环境和依赖项。

答案 1 :(得分:0)

可能没有。这类问题的标准, 但在我的情况下,我没有初始化__init__()方法中的所有参数 所以这就产生了问题 def __init__(self, value, *args, **kwargs): self.value = value super(Custom_Vali, self).__init__(*args, **kwargs)
....
....
运行
test_c = Custom_Vali.get_error(89)
OR
test_c = Custom_Vali.get_error(value = 89)

O / P:TypeError: __init__() takes at least 2 arguments (1 given)

解:
只需在__init__中设置值=无或值= 0 def __init__(self, value=0, *args, **kwargs): self.value = value super(Custom_Vali, self).__init__(*args, **kwargs)