Deploying Python App to AzureWebsites

Deploying Python App to AzureWebsites

Note: This was originally created on my azurewebsite that I learned to deploy with and can be found on my github page.

Preface
I have only been programming in Python for a few months (December 2016 to March 2017) when I decided to deploy a simple Flask app to Azure. I found that the documentation was lacking, confusing and written for someone who knew both Azure deployments and Python well which is not me.

So this is the result of what I have learned so far.
What you will need 1) an Azure account, 2) FTP Client like FileZilla, and 3) some type of IDE or text editor (Notepad, Note++ or Visual Studio Code – what I use).

Deploying a Simple Site

First, you will need an Azure account. Signup for the free tier, which allows 10 Azure Websites and 1 GB of storage (as of March 2017).

Once you have signed up to Azure.

Create a New website. Web + Mobile > See All > Search for Flask > then Create your site. Once deployed you will be able to download it via FTP.

The template looks like this.
sshot-4
Changes for you app

Web.config

Under appsettings change the FlaskWebProject1.app to whatever your app name is (folder).

Under rewrite node find the action type node url=”^/FlaskWebProject1/static/.* to you app name (folder).

App Folder Name

Change the name of the folder to whatever you named the application in web.config.
Runserver.py
Change the from FlaskWebProject1 import app to your applications name.
__init__.py
Change the import FlaskWebProject1.views to your applications name.

Views.py

Change from FlaskWebProject1 import app to your applications name.
Testing
Then run your application (python runserver.py) to make sure it all works. Default is localhost:5555, but I changed the port to 5000 and it has been running fine. If you are using a virtual environment ( pip install virtualenv and then env\Scripts\activate) then then make sure you have installed the requirements.txt ( pip install -r requirements.txt).

FTP your site to Azure

With your site working locally (localhost), its time to upload it to Azure. On the Azure portal for your Website, select QuickStart and Python. There are several options to deploy your application to Azure, for now we will use FTP. Select that as your option and follow the directions.

sshot-7.png

Once you have your credentials setup, use an FTP Client like FileZilla (what I am using) and setup a connection.

sshot-9
Once you have connected to Azure, load the entire contents of the site into Site > wwwroot.

sshot-8
It can take a few minutes for Azure to get your application running. But you should have your site up and running now.

Comments are closed.