configure python flask to be public

How to Configure Python Flask to be Externally Visible

Python Flask is a popular web framework that also ships with a lightweight server. It is used to build simple python applications and websites. By default, python flask’s server is locally accessible but not publicly accessible. Sometimes you may need to make it externally accessible. In this article, we will learn how to configure Python Flask to be externally visible.


How to Configure Python Flask to be Externally Visible

We start flask server with ‘flask run’ command. By default it is accessible only from your own computer or network, and not external IP addresses. It supports –host option that allows you to specify the hosts from which your flask server will accept incoming requests. By default, it listens to only localhost.

You can configure it to listen to requests from all hosts by setting it to 0.0.0.0. Here are two examples regarding this. The first one is the command you need to run while starting flask in terminal. The second is the code you need to use if you invoke it from within a script.

flask run --host=0.0.0.0
OR
app.run(host="0.0.0.0")

You can also set it to specific IP address by replacing 0.0.0.0 with the external IP address of your choice.

In this article, we have learnt how to configure python flask to be externally visible. But it should not be used as production server since it is not built for security, stability and scale. It is meant to be used as development server for quickly building applications and websites. Once you have tested your code, it is advisable to deploy it using a mature production server.

Also read:

How to get Difference Between Two Python Lists
How to Import Other Python File
How to Remove Punctuation from String in Python
How to Do Case Insensitive String Comparison in Python
How to Remove Duplicates from Array of Objects in JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *