gpt4 book ai didi

python - 在 django 中导入设置时出现奇怪的错误

转载 作者:太空狗 更新时间:2023-10-29 20:33:06 25 4
gpt4 key购买 nike

我有很多项目在 ubuntu 中使用 python2.7 和 virtualenv/virtualenvwrapper,在我的工作中一些开发人员使用 macosx 和 windows,通常我像往常一样创建项目:

django-admin.py start project x

我们将 svn 用于 cvs,但在某些时候,当我尝试类似的操作时,对我来说没有任何理性:

python manage.py runserver

不起作用,但仅供我使用并且在我的笔记本电脑中,这不会发生在生产服务器或其他开发人员中。

有什么想法吗?

我遇到了这个错误:

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. (If the file settings.py does indeed exist, it's causing an ImportError somehow.)

但很明显,设置文件存在并且与 manage.py 文件位于同一文件夹中,并且不适用于我...

django and appengine 也会发生这种情况

最佳答案

I got this error:

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. (If the file settings.py does indeed exist, it's causing an ImportError somehow.)

每当发生导入错误时,manage.py 脚本都会打印该警告,因此,如果您的 settings.py 模块导入内容并且导致导入错误,manage.py 仍会打印该警告。

一种诊断方法是(暂时)将 manage.py

#!/usr/bin/env python
from django.core.management import execute_manager
try:
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)

if __name__ == "__main__":
execute_manager(settings)

#!/usr/bin/env python
from django.core.management import execute_manager
import settings # Assumed to be in the same directory.

if __name__ == "__main__":
execute_manager(settings)

并查看运行 $ python manage.py runserver 时打印的堆栈跟踪。

关于python - 在 django 中导入设置时出现奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6036599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com