Deploy a Django application in Azure App Services

OrionLab
orionlab
Published in
5 min readApr 18, 2021

We will deploy a ‘helloworld’ Django application that we created in our previous article Create a Django ‘helloworld’ application using Visual Studio Code in an Azure App Services. This will give us an overview on how deploy a Django web application to a Serverless Azure App Services.

Serverless app services gives us an advantage on effortless Continuous Deployment as well as Management of your Infrastructure for your application. Another advantage is, in-case of any failures, Azure in-built features like Application Insights, Azure Monitor, for security Azure DDoS Protection Plan as well as Azure Defender, Azure Security Center will take care for your application security.

Pre-Requisite —

1. Python — Install Python in your Desktop (Download Python | Python.org)

2. Install Visual Studio Code as well (Download Visual Studio Code — Mac, Linux, Windows)

STEP — 1) Deploy an Azure App Services in your Azure Subscription. We have covered that detailed step-to-step creation in our previous article, take a look — Create an Azure App Service with GitHub Continuous Deployment Integration.

STEP — 2) We suggest users to use Visual Studio Code as it gives an easy extension to connect to your Azure Account and One-click management of your Azure Services. Download Visual Studio Code from here — Download Visual Studio Code — Mac, Linux, Windows.

STEP — 3) To create a new django application we suggest you go through our detailed article on how to Create a Django ‘helloworld’ application using Visual Studio Code. We have covered there detailed step-to-step on how to create a Django “helloworld” from scratch and used the same application here to be deployed in our Azure App Services that we created in STEP — 1.

STEP — 4) In our last article our we deployed the Django application in our localhost server and were able to browse the Helloworld webpage we have created.

Hello world in Django — Browser View — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Hello world in Django — Browser View

STEP — 5) To Deploy the application we created, we have to make small additions inside the applications that includes

  • Requirement.txt file
  • Adding Hostname inside ALLOWED_HOSTS

STEP — 5.1) Let’s create requirements.txt inside parent project directory ‘helloworldproject’

Add the following line(s) inside the requirements.txt file and save it.

Django<2.2,>=2.1.0

Note: You can use the latest version of Django as per your project requirement.

Folder Structure and Requirements.txt File — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Folder Structure and Requirements.txt File

STEP — 5.2) Let’s now add the hostname to allow access to Django application, we do this to avoid external host access and restrict DDoS attacks.

  1. Let’s get the Hostname from the App Service we created. On the right you’ll get the URL to access the App Service, copy that URL, here we have ‘https://firsthelloworldapp.azurewebsitites.net
URL to access the App Service, copy that URL — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
On The Right you’ll get the URL to access the App Service, copy that URL

2. Open ‘helloworldproject / settings.py ’ and add the copied URL removing the protocol(‘https’) from it and add firsthelloworldapp.azurewebsites.net’ in ALLOWED_HOSTS.

Add the Host URL inside allowed hosts — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Add the Host URL inside allowed hosts
ALLOWED_HOSTS = ['testhelloworldapp.azurewebsites.net']

STEP — 6) Now Let’s Add the Extension for the Azure App Services. Browser to Bottom Left to Settings Icon and Click on Extensions.

Or Use Shortcut Ctrl+Shift+X

Add Extensions inside Visual Studio Code — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Add Extensions inside Visual Studio Code

STEP — 7) Search for ‘Azure App Service’ and click on Install. Make sure provider is Microsoft.

Install Azure App Services as Extension in VS Code — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Install Azure App Services as Extension in VS Code

STEP — 8) After Installing Select your Azure Subscription in which you created your App Services. Here in Visual Studio Enterprise Subscription we have two App Services — sbapp, testhelloworldapp.

Connect Azure Account to VS Code to access App Service — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Connect Azure Account to VS Code to access App Service

STEP — 9) Click on the Blue Arrow Icon on the Top to upload your Django Project to app services.

Click on Up Arrow to upload your application — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Click on Up Arrow to upload your application

STEP — 10) Select the Parent Folder in which Django Project is created.

When we created the django-project using below command —

django-admin startproject helloworldproject

A Parent folder got created by name ‘helloworldproject ’within which it’s two subfolders ‘helloworldapp’ and ‘helloworldproject’ as well as ‘manage.py’ file.

We have to choose the Parent Folder here to upload.

Select Project folder to Upload — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Select Project folder to Upload

STEP — 11) Choose the App Service where you want to deploy the project, make sure it’s URL is mentioned in ALLOWED_HOSTS as we added in STEP — 5.2.

Here we are using ‘testhelloworldpp’.

Select the WebApp in which you want to deploy your application — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Select the WebApp in which you want to deploy your application

STEP — 12) Click on “Yes” to update the workspace configuration to run the build commands on the app services you created.

Click on “Yes” to update the workspace configuration to run the build commands on the app services you created — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Click on “Yes” to update the workspace configuration to run the build commands on the app services you created

STEP — 13) Click on “Deploy”. It will overwrite the pre-existing configuration and remove all previous deployments. You CANNOT UNDO IT.

Click on “Deploy”. It will overwrite the pre-existing configuration and remove all previous deployments — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Click on “Deploy”. It will overwrite the pre-existing configuration and remove all previous deployments

STEP — 14) Below on the Output Console, deployment will get started. Once Your Deployment is completed, click on Browse Website.

Output Console, on the top line Deployment gets started — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Output Console, on the top line Deployment gets started
Output Console, Last line where deployment has been successfully completed — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Output Console, Last line where deployment has been successfully completed
Click on browser Website to access the website — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Click on browser Website to access the website

STEP — 15) Go to the URL of the app-services, you’d be able to see the live website.

Application has successfully been deployed in Azure App Services — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Congratulations !! Application has successfully been deployed in Azure App Services

In-case the Microsoft Default website is visible, restart the Azure App Service from portal.

Restart the Azure App Service from portal in-case your Deployment is not visible — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Restart the Azure App Service from portal in-case your Deployment is not visible
Default View without Application Deployment — Deploy a Django application in Azure App Services | Orionlab | Orionlab.io
Default View without Application Deployment

Congratulations, you have successfully deployed your Django Application in a Serverless Azure App Services.

If you want to Integrate Azure SQL Servers which is a Microsoft Managed Platform as Service with your Django Application deployed in Azure App Services — Read our Article on —

This Article has been published by OrionLab.io

OrionLab | Orionlab.io | OrionLab Logo

--

--

OrionLab
orionlab
Editor for

Orionlab is a professional services company, Experts in Cloud Adoption Strategy Designing and Automation with their patented revolutionary tool — Cloudhive