How to deploy python in the AZURE app service

Bhone Myint Kyaw
3 min readJun 5, 2021

--

In this article, I am going to show how to deploy the flask python app by using visual studio 2019 and Azure portal with a few easy steps.

Step 1 — Create a python flask app in Visual Studio 2019

Select blank flask web project
Comment out some lines that will not require

Step 2 — The setup of Azure app service

We are going to create an app service with Linux os. In the setting, we are going to choose python 3.8 and this version needs to be the same as your created application in visual studio.

The setting for azure app service

After we have created the app, we are going to choose the deployment option in the deployment center. And I am going to create with the local git option.

Select source for deployment option

Moreover, you need to set up the user scope by providing a username and password to be used with FTPS and, Local Git and WebDeploy if you haven’t created one.

Setup username and password if you haven’t

Step 3 — Local git setup

In this step, we are going to make the required setup in the visual studio for the local git deployment in Azure.

Create a local git
Push to the Azure git clone uri

Now we have added the code to local git and setup the uri to push to Azure. And we need to fill up the username and password that we have created in the earlier setup.

To fill username and password

After these steps, we have deployed the website but only the default app is running, and needed to do the additional steps to see our flask app.

The default app is running

Additional Steps

We need to run the below startup command in the Azure configuration to make our flask app run.

Startup command setup
gunicorn --bind=0.0.0.0 --chdir FlaskOne --timeout 600 app:app

In this command due to the default setup of git and project structure, our app is inside the child directory so we need to add — chdir and FlaskOne is the name of the child directory ‘our project name’. Moreover, we need to add app:app if we have default python file app.py. If we have renamed the app.py to other names like helloworld.py, we need to add helloworld:app in the command.

Hello world with flask

Now we have successfully deployed the flask app with Azure app service with Visual Studio 2019.

--

--

Bhone Myint Kyaw
Bhone Myint Kyaw

Written by Bhone Myint Kyaw

Nerd coder, gamer, 24/7 watching memes

No responses yet