Django 找不到设置

发布于 2024-12-06 03:27:44 字数 647 浏览 2 评论 0原文

我有一个 Django 项目,其中包含一个“config”文件夹,其中有一个 settings_dev.py 文件,这是我的设置文件。

如果我尝试使用manage.py做任何事情,它会抱怨它找不到我的设置文件,即使我通过 --settings 选项明确提供它,例如

python manage.py syncdb --settings=config.settings_dev
Error: Can't find the file 'settings.py' in the directory containing 'manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.

但是,如果我重命名我的“ config”文件夹到“设置”,它工作正常。例如

python manage.py syncdb --settings=settings.settings_dev

工作正常。

我还需要指定什么才能让它知道我的设置文件夹实际上名为 config?

I have a Django project that contains a "config" folder, which has a settings_dev.py file inside of it which is my settings file.

If I try doing anything with manage.py, it complains that it can't find my settings file, even if I explicitly provide it via the --settings option, e.g.

python manage.py syncdb --settings=config.settings_dev
Error: Can't find the file 'settings.py' in the directory containing 'manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.

However, if I rename my "config" folder to "settings", it works fine. e.g.

python manage.py syncdb --settings=settings.settings_dev

works fine.

What else do I need to specify for it to know that my settings folder is actually named config?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

很酷不放纵 2024-12-13 03:27:44

查看manage.py。它尝试导入设置而不是conf。您必须修改您的manage.py文件

Look into manage.py. It tries to import settings not conf. You have to modify your manage.py file

半葬歌 2024-12-13 03:27:44

在指向配置模块的项目文件夹中创建一个通用的settings.py。不要忘记 config 文件夹中的 __init__.py 。这可能比修改manage.py更好。

#!/usr/bin/env python
from django.core.management import setup_environ
try:
    import config.settings as settings
except ImportError:
    import sys
    sys.stderr.write("Couldn't find the settings.py module.")
    sys.exit(1)
setup_environ(settings)

create a generic settings.py in the project folder that points to the config module. don't forget the __init__.py in the config folder. This might be better than modifying manage.py.

#!/usr/bin/env python
from django.core.management import setup_environ
try:
    import config.settings as settings
except ImportError:
    import sys
    sys.stderr.write("Couldn't find the settings.py module.")
    sys.exit(1)
setup_environ(settings)
半边脸i 2024-12-13 03:27:44

看看这个答案:

如果 settings.py 中存在导入错误,也会发生此错误。

https://stackoverflow.com/questions/6036599/bizarre-error- importing-settings-in-django#=

Have a look at this answer:

This error occurs as well if there is an import error within settings.py.

https://stackoverflow.com/questions/6036599/bizarre-error-importing-settings-in-django#=

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文