ImportError:无法导入名称连接:Mongoengine

时间:2018-01-27 10:15:36

标签: python flask flask-mongoengine

我试图通过WSGI使用Apache运行Flask应用程序,但是当我尝试连接到服务器时,我在Apache日志中标记了以下错误。有点亏。感谢任何指针。谢谢!

mod_wsgi (pid=7884): Target WSGI script '/var/www/tracker/tracker/tracker.wsgi' cannot be loaded as Python module.

mod_wsgi (pid=7884): Exception occurred processing WSGI script '/var/www/tracker/tracker/tracker.wsgi'.

 Traceback (most recent call last):
   File "/var/www/tracker/tracker/tracker.wsgi", line 3, in <module>
     from tracker import app as application
   File "/var/www/tracker/tracker/tracker.py", line 3, in <module>
     from flask_mongoengine import MongoEngine
   File "/var/www/tracker/lib/python3.5/site-packages/flask_mongoengine/__init__.py", line 6, in <module>
     import mongoengine
   File "/var/www/tracker/lib/python3.5/site-packages/mongoengine/__init__.py", line 2, in <module>
     from mongoengine import connection
ImportError: cannot import name connection

2 个答案:

答案 0 :(得分:0)

Mongoengine没有&#34;连接&#34;方法或对象。如果要连接到数据库,请使用&#34; connect(%database_name%)&#34;。

来源:http://docs.mongoengine.org/guide/connecting.html#connecting-to-mongodb

答案 1 :(得分:0)

行。所以更多的故障排除,似乎导入错误是假的,而不是看起来我遇到了Apache2 WSGI插件的问题。我错误地安装了libapache2-mod-wsgi,而且我使用Python 3.5我应该安装了libapache2-mod-wsgi-py3。

更多详情请见:

Error using mod_wsgi, Django and MongoEngine