How to setup a Python Flask application on Microsoft Azure

3 mn read

What is  Flask?

Flask is a Python framework for web development. When creating complex and large sites that are backend-heavy, you will want to use a backend framework. Currently, the 2 Python frameworks that are the most useful to learn are Flask and Django. Flask being a lightweight framework can be used to quickly set up a basic application with few lines of code.

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
   return 'Hello World'

if __name__ == '__main__':
   app.run()

What is Microsoft Azure?

Microsoft Azure is a cloud computing service created by Microsoft for building, testing deploying, and managing applications and services. Azure cloud service has app service, virtual machine,  web application firewalls, databases, and more.  All you need to deploy a test or production application is available on this service.

In this blog, we are going deploy a simple Flask application on Azure web apps service in the following steps

Step 1

Login to your Azure account. https://portal.azure.com

Step 2

In the search panel, enter “App services”

Step 3

Click on create new app service

 

onepy_deploy_flask_to_azure

Point 1 – Select a resource group or create new  group

Point 2 –  Provide a name for the application, this name forms part of the final url through which you can access your  Flask application deployed.

Point 3 –  Select the python version. Depending on your application’s python version dependency, you can currently select from python 3.7 to 3.10

Point 4 – Select the region. This part is very important, your application should be deployed as close to the users as possible i.e if users using your application will be in the US, you should deploy in that region for faster load time.

Point 5 – Select a plan. This is the payment part. You can pick a Dev or production plan. For the purpose of this blog, we will use the default plan

Point 6 –  If you use GitHub as a repository for your project,  you can configure this option. We will proceed for now.

 

Point 7 –  This is a more advanced setup that will require the setup of a virtual network out of the scope of this post.  Since we need our application to be public, the default currently works perfectly

Point 8 – Azure Monitor is a data analytics tool that offers real-time insights into the performance and health of your applications.

Point 9 –  Click on create to  complete the setup

Point 10 – Go to the app and select “Deployment Center”

Point 11 –  Select “FTPS credentials” and note the  username and password

Download Filezilla or any FTP client, and enter the username and password of the app service we recently created on Azure to upload the sample app named “app.py”. 

Once the upload is complete,   head back to your app service, under overview, and copy the URL

Load the URL on your browser to see the “Hello World”  response.

 

Ok, that’s it. You can choose to expand this app further by adding a database connection, we will look into this in subsequent blogs.

 

 

 

 

Leave a Reply

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

Reading is essential for those who seek to rise above the ordinary.

Discover Gorgo

Welcome to Gorgo, an author oriented theme.
A place where words matter. Discover without further ado our countless community stories.

Build great relations

Explore all the content form Gorgo community network. Forums, Groups, Members, Posts, Social Wall and many more. You can never get tired of it!

Become a member

Get unlimited access to the best articles on Gorgo and support our  lovely authors. Upgrade Now