In this article, we will discuss some of the essential Flask Extensions. These extensions are convenient and easy to use. So let’s look into them !!
Why do we need Flask extensions?
As we know, Flask is a micro-web framework since its core functions only include Werkzueg based WSGI, routing, and Jinja2-based Template Engine.
It can also support cookies and sessions and front-end features like JSON, static files, etc.
But this is not enough to build Full-scale Secure web applications. This is where the Flask Extensions come into the picture. With Flask-Extensions, we can perform many more tasks using the Flask framework.
There are many Flask-Extensions available. We will now look at some of the most used Flask-Extensions
Some Important Flask-Extensions
Some of the Most used Flask extensions are:
Extension | Utility |
---|---|
Flask-SQLAlchemy | It provides a model type interface to easily interact with the Database tables. |
Flask-WTF | It provides an alternative way of designing forms in the Flask web applications. Using WT Forms, we can validate and secure the Form data sent in by the user. |
Flask-Mail | It provides an SMTP interface for the Flask application to send emails to clients/users. |
Flask-Login | It provides user authentication functionality to Flask Web Applications |
Flask-Debugtoolbar | It provides a powerful debugging toolbar which is used to debug Flask applications |
Flask-Sijax | It helps to add Sijax, a Python/jQuery library that makes AJAX easy to use in web applications, support to Flask applications. |
These Extensions are Python Modules, which extends the functionalities of Flask Application. Hence we can install them just like a Python library using the pip utility.
The syntax to install a Flask-Extension “flask-foo” would be:
pip install flask-foo
#pip install flask-Sqlalchemy
#pip install flask-wtf
#pip install flask-mail
#pip install flask-login
#pip install flask-debugtoolbar
#pip install flask-sijax
The import is also similar to the way we import a python library:
from flask_foo import <Class>, <function>...
For Flask versions greater than 0.7, you can also import extensions via flask.ext.
The syntax is:
from flask.ext import foo #sqlalchemy, login .....
You can get an error if your compatibility module is not active. To activate it, use the code:
import flaskext_compat
flaskext_compat.activate()
from flask.ext import foo
Once we activate it, we can use flask.ext in same way as before.
References:
- Flask SQLAlchemy: https://flask-sqlalchemy.palletsprojects.com/en/2.x/
- Flask WT Forms: https://flask.palletsprojects.com/en/1.1.x/patterns/wtforms/
- Flask Mail: https://pythonhosted.org/Flask-Mail/
- Flask Login: https://flask-login.readthedocs.io/en/latest/
- Flask DebugToolBar: https://flask-debugtoolbar.readthedocs.io/en/latest/
- Flask Sijax: https://pythonhosted.org/Flask-Sijax/
Conclusion
That’s it, guys! This was the last article in the Flask Tutorial series. Do check out our other Flask tutorials to know more about Flask.
Happy Coding !!