Skip to content
Related Articles
Open in App
Not now

Related Articles

How to run Flask App on Google Colab?

Improve Article
Save Article
  • Last Updated : 01 Feb, 2021
Improve Article
Save Article

Flask is a web framework in python language. This means flask provides you with tools, libraries and technologies that allow you to build a web application. This web application can be some web pages, a blog, a wiki or go as big as a web-based calendar application or a machine learning webapp.

Google Colab provides a VM(virtual machine) so we cannot access the localhost(all it does it route it to our local machine’s localhost) as we do on our local machine when running a local web server. What we can do is expose it to a public URL using ngrok. Here comes the Python library flask-ngrok.

How to use Flask on Google Colab?

To create google colab file go to this link:

1) Create new notebook in google colab

2) Install library in google colab

!pip install flask-ngrok

Flask is already install on google colab so you don’t need to install it again.

3) After that lets create a simple flask app


from flask import Flask
from flask_ngrok import run_with_ngrok
app = Flask(__name__)
def home():
    return "<h1>GFG is great platform to learn</h1>"

4) To run the code on google colab press shift+enter.


Click on this link to get the output:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!