Python anywhere: Deploying a Flask server on the cloud

The objective of this post is to explain how to configure a Flask server on the cloud and create a simple hello world application.


The objective of this post is to explain how to configure a Flask server on the cloud and create a simple hello world application.

As we have seen in previous tutorials on Flask, our applications are not accessible from outside our network, unless we configure our router with port forwarding. Since port forwarding a router depends on the model of router used, this may be a complex task.

So, to avoid these unnecessary configurations, we will analyse how to deploy a Flask web server on the cloud, on pythonanywhere.

Pythonanywhere allows us to develop and host a website in the cloud. All of this can be done in a web browser, without the need to install software on our machine [1].

Pythonanywhere allows us to create a free account and start developing right away, as can be seen here. Naturally, if we need more advanced features, there are multiple paid plans.

The hello world app

The first step is to register on pythonanywhere with a free account. To do so, just follow the steps indicated in the website to create a free account. One of the best parts is that it won’t ask us for credit account information for the free account, as opposed to, for example, Microsoft Azure.

After registering, login to your account. On the page that opens, go to the web tab and select “Add a new web app”, as shown bellow in figure 1.


Figure 1 – Creating new web app.

On the popup that opens, as shown in figure 2, just hit next.


Figure 2 – App creation informative popup.

From the list of available web frameworks, select Flask, as indicated in figure 3.


Figure 3 – List of Python web frameworks.

Then, select the Python version. Choose version 3.4, which is the one used in the previous Flask tutorials.


Figure 5 – List of available Python versions.

On the new window, leave the default path  and hit next.


Figure 6 – App path configuration.

After that, wait for the configuration of the new app. A new window with your app’s configuration should appear, similar to the one in figure 7. Click on the link highlighted to test the app. Note that the “anteph” name is the one I used to register. Yours will be different.


Figure 7 – Web app configuration page.

You should get a greeting message after navigating to your app’s URL, as shown in figure 8. This is the default message for the generated  source code.


Figure 8 – Flask app default greeting message.

Now, we will change the source code of our app to output a new custom message. To do so, go back to your app’s configuration page. There, in the middle, on the Code section, select the link highlighted in figure 9.

Python anywhere config Flask app.png

Figure 9 – Navigation to the app’s source code.

You will be redirected to the project’s code directory. On this new window, click the source file, as indicated in figure 10.


Figure 10 – Code directory.

Finally, you should get to a online web editor with the source code of the Flask app. Note that this is very similar to the Hello World app we developed in this previous tutorial. Just change the return string to a custom message of your choice, then hit the save button. Finally, hit the reload button, so the code takes effect on our app.


Figure 11 – Editing the source code of the app.

Finally, reload the URL of the Python application were we have been early. You should now get the new output message we just changed, as indicating in figure 12.


Figure 12 – Custom hello world message from the changed code.





5 Replies to “Python anywhere: Deploying a Flask server on the cloud”

  1. Pingback: techtutorialsx

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s