Flask is a microweb framework written in Python that is widely used for building web applications. It is a lightweight framework that does not require particular tools or libraries to be installed. Flask provides developers with the ability to add functionality to their applications through the use of libraries and modules.
In this tutorial, we will show you how to install Flask on Debian Linux. Debian 11, also known as “Bullseye,” is the latest stable release of the Debian operating system. It is a free and open-source operating system that is widely used on servers and other systems.
Before you start, make sure that you have Python and pip installed on your system. You can check if you have Python installed by running the following command:
If you do not have Python installed, you can install it by running the following command:
sudo apt update
sudo apt install python3 python3-pip python3-venv
To check if you have pip installed, run the following command:
Step 1: Installing Flask
Once you have Python and pip installed, you can install Flask system-wide by running the following command:
`pip3 install flask`
But I recommended creating a virtual environment for your Flask application.
- Create a directory for your Flask application:
mkdir flask-app && cd flask-app
- Create the Python virtual environment.
python3 -m venv venv
- Activate the virtual environment:
- Install the Python Flask module within the virtual environment.
pip3 install flask
This will install the latest version of Flask and all the required dependencies under the virtual environment.
Step 2: Creating a Flask Application
Now that Flask is installed, you can create your first Flask application. Switch to the newly created application directory:
Next, create a file called app.py:
Add the following snippet to it:
from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Hello, World!' if __name__ == '__main__': app.run()
This code creates a simple Flask app that listens for incoming HTTP requests on the root path (/) and returns the message “Hello, World!”.
Step 3: Run Your Flask Application
To run the application, execute the following command:
This will start the Flask development server and you will see the following output:
Output:* Serving Flask app "app" * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: off * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Now, open your web browser and go to “http://127.0.0.1:5000/” to view your Flask app. You should see the message “Hello, World!” displayed on the page.
In this tutorial, you learned how to install and use Flask on Debian 11. You also learned how to create a simple Flask app and run it using the Flask development server. Flask is a powerful and easy-to-use web framework that makes it easy to build web applications with Python.