尝试将模型导入我的Google应用引擎应用时,我收到以下错误:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/app/0-1.405524594589080344/main.py", line 6, in <module>
from BaseHandler import BaseHandler
File "/base/data/home/apps/app/0-1.405524594589080344/BaseHandler.py", line 26, in <module>
from user.database import u_db
File "/base/data/home/apps/app/0-1.405524594589080344/user/database/u_db.py", line 12, in <module>
from clubs.database import fed_db, league_db, club_db
File "/base/data/home/apps/app/0-1.405524594589080344/clubs/database/fed_db.py", line 6, in <module>
from events.database import e_db
File "/base/data/home/apps/app/0-1.405524594589080344/events/database/e_db.py", line 7, in <module>
from user.database import u_db
ImportError: cannot import name u_db
我重命名了模型文件及其容器文件夹,并且可以看到这与Path有关。
我很感激在解决这个问题时给予了一些帮助,因为我被困住了。
感谢。
答案 0 :(得分:2)
您的模型中存在循环依赖关系,请参阅回溯中的这些代码:
File "/base/data/home/apps/app/0-1.405524594589080344/BaseHandler.py", line 26, in <module>
from user.database import u_db
...
File "/base/data/home/apps/app/0-1.405524594589080344/events/database/e_db.py", line 7, in <module>
from user.database import u_db
你需要解决这个问题。通常只需将import语句移动到实际需要的函数内而不是仅仅放在文件的顶部即可。但并非总是如此。