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

发布于 2024-11-07 20:32:09 字数 730 浏览 0 评论 0原文

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

django-admin.py start project x

我们使用 svn 进行 cvs,但在某些时候,没有什么合理的对我来说,当我尝试类似的操作时:

python manage.py runserver

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

有什么想法吗?

我收到这个错误:

错误:在包含的目录中找不到文件“settings.py” '管理.py'。看来你已经定制了一些东西。你必须跑 django-admin.py,将其传递给您的设置模块。 (如果文件 settings.py 确实存在,它以某种方式导致了 ImportError。)

但显然,设置文件存在并且位于 manage.py 文件的同一文件夹中,并且不仅仅对我有用...

django 和 appengine

I have many projects working in ubuntu with python2.7 and virtualenv/virtualenvwrapper, in my work some developers works with macosx and windows, generally I create the project as usual:

django-admin.py start project x

And we use svn for cvs, but in some point, without nothing rational for me, when I try something like:

python manage.py runserver

doesn't work, but is just for me and is in my laptop, that doesn't happens in productions servers or another developers.

any ideas?

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.)

But obviously, the settings file exists and is in the same folder of manage.py file, and doesn't work just for me...

This happens too with django and appengine

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

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

发布评论

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

评论(3

悸初 2024-11-14 20:32:09

我收到此错误:

错误:在包含“manage.py”的目录中找不到文件“settings.py”。看来你已经定制了一些东西。您必须运行 django-admin.py,将您的设置模块传递给它。 (如果文件 settings.py 确实存在,它会以某种方式导致 ImportError。)

每当发生导入错误时,manage.py 脚本都会打印该警告,因此如果您的 settings.py code> 模块导入内容并导致导入错误,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 时打印的堆栈跟踪。

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.)

The manage.py script prints that warning whenever an import error occurs, so if your settings.py module imports stuff and that causes an import error, manage.py will still print that warning.

One way to diagnose would be to (temporarily) change manage.py from

#!/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)

to

#!/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)

and see the stack trace that is printed when running $ python manage.py runserver.

遇到 2024-11-14 20:32:09

如果您在尝试开始使用 django 和 appengine 时遇到此错误,同时遵循 http:// www.allbuttonspressed.com/projects/djangoappengine

并且您创建了到文件夹的符号链接,创建 djangoappengine 符号链接时的指南是错误的。您需要进入 1 个目录,例如,

不:

将以下文件夹复制到您的项目中(例如,django-testapp):

django-nonrel/django => <project>/django
djangotoolbox/djangotoolbox => <project>/djangotoolbox
django-autoload/autoload => <project>/autoload
django-dbindexer/dbindexer => <project>/dbindexer
djangoappengine => <project>/djangoappengine

固定:

将以下文件夹复制到您的项目中(例如,django-testapp):

django-nonrel/django => <project>/django
djangotoolbox/djangotoolbox => <project>/djangotoolbox
django-autoload/autoload => <project>/autoload
django-dbindexer/dbindexer => <project>/dbindexer
djangoappengine/djangoappengine => <project>/djangoappengine

注意最后一行。

If you are getting this error when trying to get started with django and appengine, whilst following the guide at http://www.allbuttonspressed.com/projects/djangoappengine

and you created symlinks to the folders, the guide is wrong whilst creating the djangoappengine symlink. You need to go 1 directory e.g.

NOT:

Copy the following folders into your project (e.g., django-testapp):

django-nonrel/django => <project>/django
djangotoolbox/djangotoolbox => <project>/djangotoolbox
django-autoload/autoload => <project>/autoload
django-dbindexer/dbindexer => <project>/dbindexer
djangoappengine => <project>/djangoappengine

FIXED:

Copy the following folders into your project (e.g., django-testapp):

django-nonrel/django => <project>/django
djangotoolbox/djangotoolbox => <project>/djangotoolbox
django-autoload/autoload => <project>/autoload
django-dbindexer/dbindexer => <project>/dbindexer
djangoappengine/djangoappengine => <project>/djangoappengine

Notice the last line.

泛滥成性 2024-11-14 20:32:09

我花了一个小时搜索 django 代码,直到发现这个:

manage.py [command] --traceback

原来我的应用程序深处存在导入错误。当我看到错误后,花了十秒钟才修复。 :/

I hunted all thru the django code for an hour until I came across this:

manage.py [command] --traceback

Turns out there was an import error deep in my app. Once I could see the error, it took ten seconds to fix. :/

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