質問

I'm trying to hook flask to mongoengine. All modules seem to have been installed succesfully. Here is my import and ln 4 is where the Error is originating:

import os
from flask import Flask, render_template, send_from_directory
from mongoengine import connect
from flask.ext.mongoengine import MongoEngine

Here is the error I am getting:

File "app.py", line 4, in <module>
from flask.ext.mongoengine import MongoEngine
File "/Users/name/Desktop/venv3/lib/python2.7/site-packages/flask/exthook.py" line 87, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.mongoengine

Any ideas of what I may be doing wrong or how I can procure flask.ext.mongoengine?

役に立ちましたか?

解決

You need to install flask-mongoengine before you can use it, e.g.,

pip install flask-mongoengine

This will install a package called flask_mongoengine. Until you do that, Flask will have no knowledge about it. That is what causes your from flask.ext.mongoengine import MongoEngine statement to fail.

from flask.ext import X is a convenience inside Flask that will look for packages named flask_X (falling back to flaskext.X for legacy reasons). If you'd like to learn more about the specifics of the import hook used by Flask, the details are in exthook.py.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top