Flask extensions extend the functionality of Flask in various different ways. 比如加入数据库支持和其它的常见任务。


Flask Extension Registry中列出了 Flask 扩展,并且可以通过easy_installpip下载。如果你把一个 Flask 扩展添加到 requirements.txtsetup.py文件的依赖关系中,它们通常可以用一个简单的命令或是在你应用安装时被安装。


Extensions typically have documentation that goes along that shows how to use it. There are no general rules in how extensions are supposed to behave but they are imported from common locations. If you have an extension called Flask-Foo or Foo-Flask it should be always importable from flask_foo:

import flask_foo


While Flask Extension Registry contains many Flask extensions, you may not find an extension that fits your need. If this is the case, you can always create your own. Consider reading Flask Extension Development to develop your own Flask extension.

Flask 0.8 以前

If you are using Flask 0.7 or earlier the flask.ext package will not exist, instead you have to import from flaskext.foo or flask_foo depending on how the extension is distributed. If you want to develop an application that supports Flask 0.7 or earlier you should still import from the flask.ext package. We provide you with a compatibility module that provides this package for older versions of Flask. 你可以从GitHub下载它:flaskext_compat.py

And here is how you can use it:

import flaskext_compat

from flask.ext import foo

Once the flaskext_compat module is activated the flask.ext will exist and you can start importing from there.