English 中文(简体)
Flask - Extensions
  • 时间:2024-09-17

Flask – Extensions


Previous Page Next Page  

Flask is often referred to as a micro framework, because a core functionapty includes WSGI and routing based on Werkzeug and template engine based on Jinja2. In addition, Flask framework has support for cookie and sessions as well as web helpers pke JSON, static files etc. Obviously, this is not enough for the development of a full-fledged web apppcation. This is where the Flask extensions come in picture. Flask extensions give extensibipty to Flask framework.

There are a large number of Flask extensions available. A Flask extension is a Python module, which adds specific type of support to the Flask apppcation. Flask Extension Registry is a directory of extensions available. The required extension can be downloaded by pip utipty.

In this tutorial, we will discuss the following important Flask extensions −

    Flask Mail − provides SMTP interface to Flask apppcation

    Flask WTF − adds rendering and vapdation of WTForms

    Flask SQLAlchemy − adds SQLAlchemy support to Flask apppcation

    Flask Sijax − Interface for Sijax - Python/jQuery pbrary that makes AJAX easy to use in web apppcations

Each type of extension usually provides extensive documentation about its usage. Since an extension is a Python module, it needs to be imported for it to be used. Flask extensions are generally named as flask-foo. To import,

from flask_foo import [class, function]

For versions of Flask later than 0.7, you can also use the syntax −

from flask.ext import foo

For this usage, a compatibipty module needs to be activated. It can be installed by running flaskext_compat.py

import flaskext_compat
flaskext_compat.activate()
from flask.ext import foo
Advertisements