Bizarre error importing settings in django

我是研究僧i 提交于 2019-12-03 06:52:55

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.

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.

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. :/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!