Flask in Google Colab

Rahul Gothwal
TEK Society
Published in
2 min readNov 26, 2020

--

source: http://teksociety.tech

Want to learn/test Flask but tired of creating virtual environments?
well, this solution might help.

With this hack you will be able to run your Flask test server in google colaboratory and will be able to access it over a global IP.

To get things working, just head over to Goggle Colab

and create a new notebook and name it whatever you like.
now just connect your runtime and use this commands in the cell

!pip install flask-ngrok

this will download and install ngrok on colab virtual instance and will make your Flak apps running on localhost available over the internet via the excellent ngrok tool.

Cool, now we are ready to test our app.

the only extra line of code you need to add to your app is

from flask_ngrok import run_with_ngrokrun_with_ngrok(app)

and this will make a public IP available until your colab is running.

Now the challenge is to add other static files to the application.
well, this one is also quite simple. all you have to do is mount your google drive into the colab and create a directory for all the files you want to add into the application.

I added an HTML file to the templates directory under static and specified the path

This is how you can run your Flask application in Google cloab without installing anything onto your local machine.

--

--