FahmidasClassroom

Learn by easy steps

Feature

Python has many frameworks for developing web applications. Flask is one of the popular python frameworks that is used to develop web applications. Armin Ronacher who has developed this framework is the team leader of the Pocco project It is called a micro-framework because it does not contain ORM (Object Relation manager), URL routing, form validation, etc. like any other popular web development framework. This framework works based on Werkzeg WSGI (Web Server Gateway Interface) toolkit and the Jinja2 template engine (Transfer python variables into HTML template). Python flask can be installed after setting Python virtual environment or directly. If you want to keep the Python flask project isolated from the main Python setting then it is better to install Python virtual environment before installing flask but it requires more steps. The way to install python flask on Ubuntu without activating Python’s virtual environment has been shown in this tutorial.

Pre-requisite:

You have to install Python 3+ version in the system before installing Flask. Run the following command to check the current version of Python.

$ python3 --version

Install Python Flask:

Step-1: Update the system

Run the following command to update the system.

$ sudo apt update

Step-2: Install the Flask Framework

Run the following command to install the Python Flask.

$ sudo apt install python3-flask

Type ‘y’ to continue the installation.

Step-3: Create folder for the Flask project

Run the following command to create a project directory named flaskProject and go to the project folder.

$ mkdir flaskProject
$ cd flaskProject

Step-4: Create a file for flask application

Create a python file with the following script that will create a simple flask application.

flaskApp1.py

from flask import Flask
app = Flask(__name__)
@app.route('/')
def flask_app():
    return '<center><h3>My first flask application</h3></center>'

Step-5: Export the flask application

Run the following command to export the flask application.

$ export FLASK_APP=flaskApp1.py

Step-6: Run the application

Run the following command to run the previously created flask application in the development server.

$ flask run

Step-7: Check the output in the browser

The default port number of the flask development server is 5000. Open the following URL from any browser to check the output of the flask application.

http://127.0.0.1:5000/

Conclusion:

The most simple way to install the Python Flask framework for developing web applications has been shown in this tutorial to help python users.