Flask is a lightweight web development tool supported by the Jinja template engine and the Werkzeug WSGI toolkit. Essentially, it is referred to as a Python web framework. Various open authentication systems, form validation, upload handling, database integration, and other features are all provided via numerous extensions. It also supports extensions to add such functionality to your application as if it was added in Flask itself.
This blog will demonstrate the methods to install, use, and remove the Flask on Ubuntu 22.04.
How to install Flask on Ubuntu 22.04
Follow the below-listed steps to install Flask on Ubuntu 22.04.
Step 1: Install Python environment
In the first step, install the Python3 environment and pip using provided command:
$ sudo apt install python3-venv pip -y
Step 2: Create new directory
Create a new directory as we have created “itslinux_Flask”:
$ mkdir itslinux_Flask
Open the newly created directory using “cd” command:
$ cd itslinux_Flask
Step 3: Activate the Created Environment
Perform virtual environment activation by utilizing the provided command:
$ python3 -m venv venv && source venv/bin/activate
Step 4: Install Flask
Now install Flask by using the following “pip” command:
$ pip install Flask
By examining Flask version, let’s verify the installation:
$ python -m flask --version
As you can see, “Flask 2.1.2” was successfully installed. Come on! Let’s start using it on the Ubuntu 22.04.
How to use Flask on Ubuntu 22.04
Follow the instructions below to use Flask on Ubuntu 22.04.
Step 1: Open Flask_application.py file
First create and open up a new file in nano editor using provided command:
$ nano Flask_application.py
Step 2: Create Flask application
In the opened file, add the code given below, use “CTRL+S” to save the file, and “CTRL+X” to close the nano editor:
from flask import Flask app = Flask(__name__) @app.route('/') def my_flask_application(): return 'Welcome to first [email protected] application'
Step 3: Export Flask_application.py file
Export the newly created application “Flask_application.py” file:
$ export FLASK_APP=Flask_application.py
Step 4: Run Flask
In the final step, run Flask using the listed command and copy the highlighted link:
$ flask run
Paste the copied link on the browser. As you can see, our new application has been successfully developed:
Now, let’s remove Flask from Ubuntu 22.04.
How to remove Flask from Ubuntu 22.04
On Ubuntu 22.04, to remove Flask use the provided command:
$ pip uninstall Flask
Then deactivate the virtual environment:
We have efficiently described how to install, use, and remove Flask on Ubuntu 22.04.
On Ubuntu 22.04, to install Flask, first install and activate the virtual environment. Then create and open a new directory and install Flask using the “$ pip install Flask” command on the Ubuntu terminal. After that, create a new application in the nano editor and launch Flask by visiting the “http://127.0.0.1:5000” address in a web browser. The instructions for installing, using, and removing Flask on Ubuntu 22.04 have been clearly explained in our today’s post.