Convert Python Console App to Web App With Flask

In this blog post, I will show you how to convert a Python console app to a Web App using Flask.

About Flask

Flask is a web development framework for Python that gives the capabilities to convert a console app into a Web App.

Using Flask, we can take a Python app running in a console and run in a browser.

Install Flask

To install flask, we use the following command.

pip install flask

Run flask

Below is a basic Flask application that runs a simple Python code in the browser.

from flask import Flask
app = Flask(__name__)
def hello():
return "Hello World!"
if __name__ == "__main__":

When we run the code, we will use the flask webserver to view the app using our browser.

In our case, the webserver URL is.

When I click on the URL, I can see my program is running.

I can also use a more sophisticated example of a console app that generates a number.

Below is the code I am using.

import random
import string
from flask import Flask
app = Flask(__name__)
def rannum():
x =random.randint(500000,9000000)
y = str(x)
return y
if __name__ == '__main__':

The result is shown below.

Success! You're on the list.