English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Flask Extensions

Flask is usually called a micro-framework because its core features include WSGI and routing based on Werkzeug, as well as templating based on Jinja2The template engine. In addition, the Flask framework also supports cookies and sessions as well as web assistants such as JSON, static files, and so on. It is obvious that this is not enough for developing a complete web application. This is why Flask extension plugins are still needed. Flask extensions provide extensibility for the Flask framework.

Flask has a large number of extensions available. A Flask extension is a Python module that adds specific types of support to Flask applications. The Flask extension registry is a directory of available extensions. The required extension can be downloaded using the pip utility.

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

Flask Mail − Provides an SMTP interface for Flask applications Flask WTF − Added rendering and validation for WTForms Flask SQLAlchemy − Add SQLAlchemy support to Flask applications Flask Sijax − Sijax interface - Making AJAX easy to use in web applications with Python/jQuery library

Each type of extension usually provides a large amount of documentation on its usage. Since an extension is a Python module, it needs to be imported before it can be used. Flask extension names are usually named flask-foo. The import syntax is as follows,

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
from flask_foo import [class, function]

for versions below 0.7of the Flask version, and you can also use the syntax -

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
from flask.ext import foo

To do this, you need to activate the compatibility module. It can be installed by running flaskext_compat.py -

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : www.oldtoolbag.com
# Date : 2020-08-08
import flaskext_compat
 flaskext_compat.activate()
 from flask.ext import foo