【问题标题】:ImportError from modular django settings file来自模块化 django 设置文件的 ImportError
【发布时间】:2011-06-14 03:16:10
【问题描述】:

我正在尝试创建模块化设置文件。

为什么会这样:

project/
  settings.py
  other.py

在settings.py中使用这一行

config_module = __import__('other', globals(), locals())

虽然以下会引发 ImportError:

project/
  settings.py
  config/
    other.py

在 settings.py 中有这一行:

config_module = __import__('config.other', globals(), locals())

【问题讨论】:

  • 您在配置目录中是否缺少__init__.py

标签: python django django-settings


【解决方案1】:

看起来您的配置目录缺少 __init__.py 文件,以明确您希望将其视为模块。 __init__.py 文件可以为空,但必须存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-03
    • 2011-06-23
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多