Bizarre error importing settings in django

依然范特西╮ 提交于 2019-12-04 12:10:56

问题


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


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/6036599/bizarre-error-importing-settings-in-django

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