How To Deploy Django In Azure ?
Last Updated :
27 Mar, 2024
In this tutorial, we'll deploy the Python (Django) Web app to Azure. Microsoft Azure provides an environment for websites to be deployed, managed, and scaled very easily. We'll see two options to deploy our Django website - one using Azure CLI and the other using Azure Portal's Interface. The deployed website will be deployed on Azure subdomain but if you have your own registered domain name then you can also use that. Let's dive into the tutorial.
What is Azure?
Azure is a cloud computing platform that is provided by Microsoft and is commonly referred to as Microsoft Azure. This platform provides a wide variety of services like storage, Virtual Machines, databases, AI, Machine Learning, Virtual Networks, functions, and the list goes on and on. If you want to learn more about it, Microsoft itself provides its Learning platform, or visit the GFG page to learn more.
What is Django?
Django is a web framework written in Python, which is used to build web applications quickly. It is based on MVC architecture and follows the DRY (Don't Repeat Yourself) principle. It is famously known for its built-in features for admin interface, database, ORM, forms handling, testing framework, etc. which makes it a popular choice among developers, mostly Python developers to use it for designing Web Applications. You can learn more by visiting the GFG Django tutorial.
Prerequisite:
- A Django project ready for deployment.
- Azure Account.
Implementation:
Deploy using Azure CLI (Best Option) :
Step 1: First download and Install Azure CLI on your local system. Visit here to download Azure CLI according to your OS and present tools.
Step 2: Check your Azure version by typing:
az version

Step 3: Now login to Azure using CLI :
az login
Typing above command will open login page on Browser, then login using your credentials and that will display successful window on Browser:
Successful Login window in BrowserAnd CLI will display result like this on successful Login:
Output Result after Successful Login in CLIStep 4: Now we'll create the app and other required resources in one command. Remember to be in your Web Application directory because below command automatically takes the files from the current directory with automatically production building.
az webapp up --runtime PYTHON:3.9 --sku B1 --logs
- here --runtime refers to the python version the app is using.
- --sku tells to use the B1 (Baisc) service plan, you can choose appropriate plan for your website.
- here the website name will be generated automatically, but you can specify the app name by using --name mywebsitename
- --logs print the logs in the console.
What Above command does?
- creates resource group
- creates App Service Plan
- create app with specified name or if not given the generates name automatically
- zip deployment
The above command automatically creates and configures everything required for a website from creating resource group to zip deployment. Everything that goes in cloud is printed step by step in the CLI, see the below image to know how it looks
Console Output of deployed WebsiteStep 5: Now your website is deployed on Azure App Service. You can access your website at http://<app-name>.azurewebsites.net
Like my app name is 'kind-bush-1d842db2ea724133a92a92d5696d8466' so i can access my website at 'https://kind-bush-1d842db2ea724133a92a92d5696d8466.azurewebsites.net/
You can check your website configuration in App Services in Azure Portal.
Deploy using Azure Portal:
Step 1: Search for App Services in Search Bar and Select that.
Step 2: Click on the '+ Create' option and then select 'web app'.
App Services dashboardStep 3: Now fill the details in Create Web App.
- Select/create resource group.
- write a unique name of your website which will also act as domain for your website
- Select Runtime Stack as your Python version, mine is python 3.9
- Select the region which is close to you or your client.
- Select the pricing plan for your website, I'll select this time F1.
Filling App details
Selecting the Pricing Plans for WebsiteStep 4: Now click on 'Review+Create' or you can explore more configuration according to your Website like Database and Networking etc. And then Click on 'Create'
Click on Create.Step 5: Now we have to upload the app code on Azure. For that create a ZIP of your website files. In first few steps we'll do the configuration required to upload the Zip file and after that we'll see on how to do zip deployment either by using curl or Azure CLI
Click on Configuration under Setting tab on left and then select New Application Setting.
ConfigurationStep 6: Now in name write SCM_DO_BUILD_DURING_DEPLOYMENT and in value fill true and then click on OK and then click on Save in the Configuration window (beside the Refresh and Discard options).
Add/Edit Application SettingStep 7: Now click on Continue to save the Configuration and automatically restart to apply the changed settings.
Save ConfigurationStep 8: Now click on Deployment Center in Deployment tab in left sidebar and select the FTPS credentials bar. In the FTPS Username select only part after '\' that starts with $ like here $Brahmbeyonddjango.
FTPS credentialsStep 9: Here as you can see that by default there is a warning that FPT has been disabled and if this isn't your case then skip this step. Head to Configuration under Setting tab on left sidebar and click on General settings.
General settingsNow click on 'ON' radio button in FTP Basic Auth section
Enabling the FTP AuthNow head back to Deployment Center and you'll see that warning is gone.
Step 10: Option a: Use this curl command to upload the zip file of your Django website and deploy it.
curl -X POST \
-H 'Content-Type: application/zip' \
-u '<deployment-user>' \
-T <zip-file-name> \
https://<app-name>.scm.azurewebsites.net/api/zipdeploy
curl -X POST -H 'Content-Type: application/zip' -u '<deployment-user>' -T <zip-file-name> https://<app-name>.scm.azurewebsites.net/api/zipdeploy
Replace the '<deployment-user> with the username you got in previous step, and <zip-file-name> with your zip file name and the <app-name> with your app name.
This will upload the zip files and deploy your website on azure.
Option b: If you will face problem with the curl, you can use Azure CLI (first you need to install if you haven't yet as Azure CLI will be very helpful if you plan to use Azure)
- If you have bash: (Commands taken directly from Microsoft Azure tutorial)
# Change these values to the ones used to create the App Service.
RESOURCE_GROUP_NAME='msdocs-python-webapp-quickstart'
APP_SERVICE_NAME='msdocs-python-webapp-quickstart-123'
az webapp deploy --name $APP_SERVICE_NAME --resource-group $RESOURCE_GROUP_NAME --src-path <zip-file-path>
- If you have PowerShell: (Command taken directly from Microsoft Azure tutorial)
# Change these values to the ones used to create the App Service.
$resourceGroupName='msdocs-python-webapp-quickstart'
$appServiceName='msdocs-python-webapp-quickstart-123'
az webapp deploy --name $appServiceName --resource-group $resourceGroupName --src-path <zip-file-path>
Now your website is deployed on Azure App Service. You can access your website at http://<app-name>.azurewebsites.net
Like my app name is 'Brahmbeyonddjango' so i can access my website at 'https://Brahmbeyonddjango.azurewebsites.net/'
Conclusion
Whether you want use CLI interface or azure's user-friendly GUI, now you know how to deploy your Django website easily. You can explore other configuration options as it's a cloud platform with very large features and everyone's Applications configurations depends on their needs.
Similar Reads
How to Deploy Django Application in AWS EC2? In this article, we will study how we can deploy our existing Django web application to Windows Server in AWS EC2. We will also see how to use the public IP of the EC2 instance to access the Django application. For this article, you should know about setting up EC2 in AWS. We will see how to deploy
3 min read
How to Deploy Django Application in AWS Lambda? Pre-requisite: AWS , Python Django is a Python web framework that makes it easy to build web applications quickly and securely. It has a large and helpful community that provides support and contributes to its development. AWS Lambda is a serverless computing platform that runs your code in Docker c
7 min read
How to Deploy a Django Application in Kubernetes In this article, we will study how we can deploy Django web applications to Kubernetes. We will also see how to dockerize and build an image of the Django application using Dockerfile. For this article, you should know about setting up a VM in Azure. We will see how to deploy applications on Linux S
5 min read
Deploy a Node.js Application with Azure Deploying a Node.js application on Azure, a prominent cloud computing platform, has become a seamless process, thanks to its user-friendly interface and integration capabilities. This guide aims to walk you through deploying a Node.js application on Azure using the Azure portal. We will cover essent
4 min read
How to Deploy Flask App on Kubernetes? A lightweight Python framework providing simplicity and flexibility in development, Flask can be utilized to create web applications. In contrast, Kubernetes is an effective framework for container orchestration that facilitates the deployment, scaling, and management of containerized applications.
6 min read