How to deploy python in the AZURE app service
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
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.
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.
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.
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.
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.
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.
Additional Steps
We need to run the below startup command in the Azure configuration to make our flask app run.
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.
Now we have successfully deployed the flask app with Azure app service with Visual Studio 2019.