Skip to content
Myr

extensions.rst

This file

Path

docs/extensions.rst

48 lines · 1.8 KiB

Last changed by

Reworded before 0.8 ext docs.Armin Ronacherbefore adoption4573715

History of this file

Take it

Started extensions introduction documentArmin Ronacherbefore adoption933d203

lines 1–25why, one step back
1Flask Extensions
2================34Flask extensions extend the functionality of Flask in various different5ways. For instance they add support for databases and other common tasks.67Finding Extensions8------------------910Flask extensions are listed on the `Flask Extension Registry`_ and can be11downloaded with ``easy_install`` or ``pip``. If you add a Flask extension12as dependency to your ``requirements.rst`` or ``setup.py`` file they are13usually installed with a simple command or when your application installs.1415Using Extensions16----------------1718Extensions typically have documentation that goes along that shows how to19use it. There are no general rules in how extensions are supposed to20behave but they are imported from common locations. If you have an21extension called ``Flask-Foo`` or ``Foo-Flask`` it will be always22importable from ``flask.ext.foo``::2324 from flask.ext import foo25

Reworded before 0.8 ext docs.Armin Ronacherbefore adoption4573715

lines 26–27why, one step back
26Flask Before 0.8
27----------------

Started extensions introduction documentArmin Ronacherbefore adoption933d203

lines 28–30why, one step back
28
29If you are using Flask 0.7 or earlier the :data:`flask.ext` package will not30exist, instead you have to import from ``flaskext.foo`` or ``flask_foo``

Reworded before 0.8 ext docs.Armin Ronacherbefore adoption4573715

lines 31–35why, one step back
31depending on how the extension is distributed. If you want to develop an
32application that supports Flask 0.7 or earlier you should still import33from the :data:`flask.ext` package. We provide you with a compatibility34module that provides this package for older versions of Flask. You can35download it from github: `flaskext_compat.py`_

Started extensions introduction documentArmin Ronacherbefore adoption933d203

line 36why, one step back
36

Explicitly activate compat moduleArmin Ronacherbefore adoption7997bae

line 37why, one step back
37And here is how you can use it::

Started extensions introduction documentArmin Ronacherbefore adoption933d203

lines 38–39why, one step back
38
39 import flaskext_compat

Explicitly activate compat moduleArmin Ronacherbefore adoption7997bae

lines 40–41why, one step back
40 flaskext_compat.activate()
41

Started extensions introduction documentArmin Ronacherbefore adoption933d203

lines 42–43why, one step back
42 from flask.ext import foo
43

import -> activateArmin Ronacherbefore adoption2b8ea40

line 44why, one step back
44Once the ``flaskext_compat`` module is activated the :data:`flask.ext` will

Started extensions introduction documentArmin Ronacherbefore adoption933d203

lines 45–48why, one step back
45exist and you can start importing from there.
4647.. _Flask Extension Registry: http://flask.pocoo.org/extensions/48.. _flaskext_compat.py: https://github.com/mitsuhiko/flask/raw/master/scripts/flaskext_compat.py