Deploy a Python (Django or Flask) web app with PostgreSQL in Azure
Article
33 minutes to read
In this tutorial, you'll deploy a data-driven Python web app (Django or Flask) with the Azure Database for PostgreSQL relational database service. The Python app is hosted in a fully managed Azure App Service which supports Python 3.7 or higher in a Linux server environment. You can start with a basic pricing tier that can be scaled up at any later time.
To complete this tutorial, you'll need:
An Azure account with an active subscription exists. If you don't have an Azure account, you can create one for free.
Sample Python applications using the Flask and Django framework are provided to help you follow along with this tutorial. Download or clone one of the sample applications to your local workstation.
If you are following along with this tutorial with your own app, look at the requirements.txt file description in each project's README.md file (Flask, Django) to see what packages you'll need.
Set environment variables to specify how to connect to a local PostgreSQL instance.
This sample application requires an .env file describing how to connect to your local PostgreSQL instance. Create an .env file using the .env.sample file as a guide. Set the value of DBNAME to the name of an existing database in your local PostgreSQL instance. This tutorial assumes the database name is restaurant. Set the values of DBHOST, DBUSER, and DBPASS as appropriate for your local PostgreSQL instance.
For Django, you can use SQLite locally instead of PostgreSQL by following the instructions in the comments of the settings.py file.
In a web browser, go to the sample application at http://localhost:5000 and add some restaurants and restaurant reviews to see how the app works.
In a web browser, go to the sample application at http://localhost:8000 and add some restaurants and restaurant reviews to see how the app works.
Tip
With Django, you can create users with the python manage.py createsuperuser command like you would with a typical Django app. For more information, see the documentation for django django-admin and manage.py. Use the superuser account to access the /admin portion of the web site. For Flask, use an extension such as Flask-admin to provide the same functionality.
Sign in to the Azure portal and follow these steps to create your Azure App Service resource.
Instructions
Screenshot
In the Azure portal:
Enter app services in the search bar at the top of the Azure portal.
Select the item labeled App Services under the under Services heading on the menu that appears below the search bar.
On the App Services page, select + Create.
On the Create Web App page, fill out the form as follows:
Resource Group → Select Create new and use a name of msdocs-python-postgres-webapp-rg.
Name → Use msdocs-python-postgres-webapp-<unique-id>. The name must be unique across Azure with the web app's URL https://<app-service-name>.azurewebsites.com).
Runtime stack → Python 3.9
Region → Any Azure region near you.
App Service Plan → Select Create new under Linux Plan and use the name of msdocs-python-postgres-webapp-plan.
App Service Plan → Select Change size under Sku and size to select a different App Service plan.
In the Spec Picker section, select an App Service plan. The App Service plan controls how many resources (CPU/memory) are available to your app and the cost of those resources.
Select Dev/Test.
Select B1 (Basic) Plan.
The B1 Basic plan will incur a small charge against your Azure account but is recommended for better performance over the F1 (Free) plan.
Select Apply.
Back on the Create Web App page, select the Review + create button at the bottom of the screen.
This will take you to a page to review the configuration. Select Create to create your App Service.
To create Azure resources in VS Code, you must have the Azure Tools extension pack installed and be signed into Azure from VS Code.
Locate the Azure icon in the left-hand toolbar and select it to bring up the Azure Tools for VS Code extension.
If you do not see the Azure tools icon, make sure you have the Azure Tools extension for VS Code installed.
In the Azure Tools extension:
Expand RESOURCES and find your subscription. (Make sure resources are grouped by resource type.)
Right-click App Services in your subscription.
Select Create New Web App...(Advanced).
In the dialog box at the top of the screen, enter the name of msdocs-python-postgresql-webapp-<unique-id> for this web app.
The name must be unique across Azure. When deployed, this name is used in the DNS name of the web app is https://<app-service-name>.azurewebsites.net.
Select Create New Resource Group and enter msdocs-python-postgres-webapp-rg in the prompt, if the resource group does not already exist.
Select the runtime stack for the application. For this example, select Python 3.9.
Select a region/location near you, such as eastus.
Configure Linux App Service Plan:
Select Create new App Service plan.
Enter msdocs-python-postgres-webapp-plan or use the auto-generated name.
Select the App Service plan pricing tier for this web app.
The App Service plan controls how many resources (CPU/memory) are available to your app and how much you pay. For this example, it's recommended to select the Basic (B1) Develop and test pricing tier. This will incur a small cost in your Azure subscription but provides better performance than the Free (F1) tier.
Skip adding Application Insights to your web app by selecting Skip for now.
After the last choice, the Azure starts to create the app service.
View the output and browse to the website:
When a message appears indicating that the new App Service was created, select View Output to switch to the Output window in VS Code.
To confirm that the App Service is running properly, right-click the App Service name, and select Browse Website.
Because you haven't deployed your own code to the App Service yet (which you do in a later step), only a default app page appears.
Step 1. Create a resource group using the az group create command. A resource group will act as a container for all of the Azure resources related to this application.
LOCATION='eastus'
RESOURCE_GROUP_NAME='msdocs-python-postgres-webapp-rg'
# Create a resource group
az group create \
--location $LOCATION \
--name $RESOURCE_GROUP_NAME
$LOCATION='eastus'
$RESOURCE_GROUP_NAME='msdocs-python-postgres-webapp-rg'
# Create a resource group
az group create `
--location $LOCATION `
--name $RESOURCE_GROUP_NAME
location → A location near you, for example eastus. Use az account list-locations --output table to list locations.
name → You will use this resource group to organize all the Azure resources needed to complete this tutorial. (for example, msdocs-python-postgres-webapp-rg)
APP_SERVICE_PLAN_NAME='msdocs-python-postgres-webapp-plan'
az appservice plan create \
--name $APP_SERVICE_PLAN_NAME \
--resource-group $RESOURCE_GROUP_NAME \
--sku B1 \
--is-linux
$APP_SERVICE_PLAN_NAME='msdocs-python-postgres-webapp-plan'
az appservice plan create `
--name $APP_SERVICE_PLAN_NAME `
--resource-group $RESOURCE_GROUP_NAME `
--sku B1 `
--is-linux
name → Name for the Azure Web App plan, msdocs-python-postgres-webapp-plan
resource-group → Use the same resource group name you used when you created the web app, for example msdocs-python-postgres-webapp-rg.
sku → Defines the size (CPU, memory) and cost of the app service plan. This example uses the B1 (Basic) service plan, which will incur a small cost in your Azure subscription. For a full list of App Service plans, view the App Service pricing page.
is-linux → Selects Linux as the host operating system.
Step 3. Create the App Service web app using the az webapp create command.
name → The app service name is used as both the name of the resource in Azure and to form the fully qualified domain name for your app in the form of the server endpoint https://<app-service-name>.azurewebsites.com. This name must be unique across all Azure and the only allowed characters are A-Z, 0-9, and -. For example, use msdocs-python-postgres-webapp-\<unique-id> where \<unique-id> is any three characters.
runtime → The runtime specifies what version of Python your app is running. This example uses Python 3.9. To list all available runtimes, use the command az webapp list-runtimes --os linux --output table.
plan → Use the same app service plan name from Step 2. (msdocs-python-postgres-webapp-plan)
resource-group → Use the same resource group name from Step 1. (msdocs-python-postgres-webapp-rg)
Note
This tutorial shows step-by-step use of Azure CLI commands to reinforce the logical steps that go into creating and deploying an App Service. Once you get familiar with the steps, you can try the az webapp up that creates a webapp and deploys its code from a local workspace to App Service.
Sign in to the Azure portal and follow these steps to create your Azure Database for PostgreSQL resource.
Instructions
Screenshot
In the Azure portal:
Enter postgres in the search bar at the top of the Azure portal.
Select the item labeled Azure Database for PostgreSQL flexible servers under the under Services heading on the menu that appears below the search bar.
On the Azure Database for PostgreSQL flexible servers page, select + Create
On the next page, select Create under Flexible server.
On the Flexible server page, fill out the form as follows:
Resource group → Select and use a name of msdocs-python-postgres-webapp-rg.
Server name → Enter a name such as msdocs-python-postgres-webapp-db-<unique-id>. The name must be unique across Azure with the database server's URL https://<server-name>.postgres.database.azure.com). Allowed characters are A-Z, 0-9, and -.
Region → Same Azure region used for the Web App.
Data source → None
Workload type → Production
Compute + storage → Select Configure server to select a different Compute + storage plan, which is discussed below.
Availability zone → Keep the default (which is no preference).
Version → Keep the default (which is the latest version).
On the Compute + storage page, continue configuring the flexible server:
Compute tier → Select Burstable.
Compute size → Select Standard_B1ms.
Select Save to return to the main configuration page.
Back on the main Flexible server page, finish the basic configuration:
Administrator account → Enter a Admin username and Password to be used for the database administrator account.
Select Next: Networking at the bottom of the screen.
On the Networking page, add a firewall rule that allows your local environment to access the database server:
Select Add current client IP address to allow access from your local environment.
Select Review + Create at the bottom of the screen.
This will take you to the Review page. Select Create to create your Azure Database for PostgreSQL Flexible Server Service.
In your local environment using the PostgreSQL interactive terminal psql, connect to the PostgreSQL database server, and create the restaurant database:
The values of <server-name> and <admin-user> are the values from a previous step. If you have trouble connecting, restart the database and try again.
Optionally, verify that the restaurant database was successfully created by running \c restaurant to change the prompt from postgres (default) to the restaurant. Type \? to show help or \q to quit.
Follow these steps to create your Azure Database for PostgreSQL resource using the Azure Tools extension pack in Visual Studio Code.
Instructions
Screenshot
In Visual Studio Code, select the Azure Tools extension. Sign into Azure, if you haven't already.
In the Azure Tools extension:
Expand RESOURCES. (Make sure resources are sorted by resource type.)
Under your subscription, right-click PostgresSQL servers (Flexible) and select Create Server.
Select PostgreSQL Flexible Server from the list.
In the VS Code prompts, enter the following information:
Server name → Enter a name for the database server that's unique across all Azure (the database server's URL becomes https://<server-name>.postgres.database.azure.com). Allowed characters are A-Z, 0-9, and -. For example: msdocs-python-postgres-webapp-db-<unique-id>.
Select the Postgres SKU and options → Select B1ms Basic, 1 vCore, 2GiB Memory, 32GB storage.
Administrator Username and Administrator Password → Enter credentials for an administrator account on the database server. Record these credentials as you'll need them later in this tutorial.
Select a resource group → Select the resource group you created the App Service in, for example msdocs-python-postgres-webapp-rg.
Select a location → Select the same location as the App Service.
Once the database is created, configure access from your local environment to the PostgreSQL database server:
Open the Command Palette (Ctrl + Shift + P).
Search for select PostgreSQL: Configure Firewall.
Select a subscription if prompted.
Select the database you created above, for example msdocs-python-postgres-webapp-db-<unique-id>. If the database name doesn't appear in the list, it's likely it hasn't finished being created.
Select Yes in the dialog box to add your IP address to the firewall rules of the PostgreSQL server.
After the firewall rule allowing local access has been successfully added, create the restaurant database.
Under your subscription, find the PostgreSQL Server you created (for example, msdocs-python-postgres-webapp-db-<unique-id>), right-click and select Create Database.
Enter restaurant as the Database Name.
If you have trouble creating the database, the server may still be processing the firewall rule from the previous step. Wait a moment and try again.
Run az login to sign in to and follow these steps to create your Azure Database for PostgreSQL resource.
Step 1. Run the az postgres flexible-server create command to create the PostgreSQL server and database in Azure using the values below. It is not uncommon for this command to run for a few minutes to complete.
resource-group → Use the same resource group name in which you created the web app, for example msdocs-python-postgres-webapp-rg.
name → The PostgreSQL database server name. This name must be unique across all Azure (the server endpoint becomes https://<name>.postgres.database.azure.com). Allowed characters are A-Z, 0-9, and -. A good pattern is to use a combination of your company name and server identifier. (msdocs-python-postgres-webapp-db)
location → Use the same location used for the web app.
admin-user → Username for the administrator account. It can't be azure_superuser, admin, administrator, root, guest, or public. For example, demoadmin is okay.
admin-password Password of the administrator user. It must contain 8 to 128 characters from three of the following categories: English uppercase letters, English lowercase letters, numbers, and non-alphanumeric characters.
Important
When creating usernames or passwords do not use the $ character. Later you create environment variables with these values where the $ character has special meaning within the Linux container used to run Python apps.
public-access → None which sets the server in public access mode with no firewall rules. Rules will be created in a later step.
sku-name → The name of the pricing tier and compute configuration, for example Standard_B1ms. Follow the convention {pricing tier}{compute generation}{vCores} set create this variable. For more information, see Azure Database for PostgreSQL pricing.
resource-group → Use the same resource group name in which you created the web app, for example msdocs-python-postgres-webapp-rg.
name → The PostgreSQL database server name.
rule-name → AllowMyIP.
start-ip-address → equal to your IP address. To get your current IP address, see WhatIsMyIPAddress.com.
end-ip-address → equal to start-ip-address.
Step 3. (optional) You can retrieve connection information using the az postgres server show. The command outputs a JSON object that contains connection strings for the database along and the administratorLogin name.
az postgres flexible-server show \
--name $DB_SERVER_NAME \
--resource-group $RESOURCE_GROUP_NAME
az postgres flexible-server show `
--name $DB_SERVER_NAME `
--resource-group $RESOURCE_GROUP_NAME
resource-group → The name of resource group you used, for example, msdocs-python-postgres-webapp-rg.
name → The name of the database server, for example, msdocs-python-postgres-webapp-db-<unique-id>.
Step 4. In your local environment using the PostgreSQL interactive terminal psql, connect to the PostgreSQL database server, and create the restaurant database.
The values of <server name> and <admin-user> are the values from a previous step. If you have trouble connecting, restart the database and try again.
Step 5.(optional) Verify restaurant database was successfully created by running \c restaurant to change the prompt from postgres (default) to restaurant.
After the Azure Database for PostgreSQL server is created, configure access to the server from the web app by adding a firewall rule. This can be done through the Azure portal or the Azure CLI.
If you're working in VS Code, right-click the database server and select Open in Portal to go to the Azure portal. Or, go to the Azure Cloud Shell and run the Azure CLI commands.
az postgres server firewall-rule create --resource-group $RESOURCE_GROUP_NAME \
--server $DB_SERVER_NAME \
--name AllowAllWindowsAzureIps \
--start-ip-address 0.0.0.0 \
--end-ip-address 0.0.0.0
az postgres server firewall-rule create --resource-group $RESOURCE_GROUP_NAME `
--server $DB_SERVER_NAME `
--name AllowAllWindowsAzureIps `
--start-ip-address 0.0.0.0 `
--end-ip-address 0.0.0.0
resource-group → Name of resource group from earlier in this tutorial. (msdocs-python-postgres-webapp-rg)
server → Name of the server from Step 1. (msdocs-python-postgres-webapp-db)
name → Name for firewall rule. (use AllowAllWindowsAzureIps)
start-ip-address, end-ip-address → 0.0.0.0 signals that access will be from other Azure services. This is sufficient for a demonstration app, but for a production app you should use an Azure Virtual Network.
With the web app and PostgreSQL database created, the next step is to connect the web app to the PostgreSQL database in Azure.
The web app code uses database information in four environment variables named DBHOST, DBNAME, DBUSER, and DBPASS to connect to the PostgresSQL server.
In the portal, go to the App Service page for the web app.
Select Configuration under Settings on the left side.
Select Application settings at the top of the page.
Create application settings:
Select + New application setting to create settings for each of the following values (which are expected by the django sample app):
DBHOST → Use the server name you used earlier when created the database, for example, msdocs-python-postgres-webapp-db-<unique id>.
The code in azuresite/production.py automatically appends .postgres.database.azure.com to create the full PostgreSQL server URL.
DBNAME → Enter restaurant, the name of the application database.
DBUSER → The administrator user name used when you provisioned the database.
DBPASS → The administrator secure password you created earlier.
Confirm you have four settings and view their hidden values.
Select Save and to apply the settings.
To configure environment variables for the web app from VS Code, you must have the Azure Tools extension pack installed and be signed into Azure from VS Code.
Instructions
Screenshot
Locate the Azure icon in the left-hand toolbar and select it to bring up the Azure Tools for VS Code extension.
In the Azure Tools extension:
Expand RESOURCES. (Make sure resources are sorted by resource type.)
Locate your web app, expand its node, and right-click Application Settings to bring up the context menu.
Select Add new setting... from the menu.
In the dialog box at the top of the VS Code window, add each setting name followed by its value.Add the following settings:
DBHOST → Enter the server name you used earlier when created the database, for example, msdocs-python-postgres-webapp-db-<unique-id>. The code in azuresite/production.py automatically appends .postgres.database.azure.com to create the full PostgreSQL server URL.
DBNAME → Enter restaurant.
DBUSER → Enter the administrator user name you specified when creating the database. The code in azuresite/production.py automatically constructs the full Postgres username from DBUSER and DBHOST, so don't include the @server portion.
DBPASS → Enter the administrator password you specified when creating the database. The code in azuresite/production.py automatically constructs the full Postgres username from DBUSER and DBHOST, so don't include the @server portion.
To set environment variables in App Service, you create app settings with the following az webapp config appsettings set command.
az webapp config appsettings set \
--resource-group $RESOURCE_GROUP_NAME \
--name $APP_SERVICE_NAME \
--settings DBHOST=$DB_SERVER_NAME DBNAME=$DB_NAME DBUSER=$ADMIN_USERNAME DBPASS=$ADMIN_PWD
az webapp config appsettings set `
--resource-group $RESOURCE_GROUP_NAME `
--name $APP_SERVICE_NAME `
--settings DBHOST=$DB_SERVER_NAME DBNAME=$DB_NAME DBUSER=$ADMIN_USERNAME DBPASS=$ADMIN_PWD
DBHOST → Use the name of the name you used earlier with the az postgres flexible-server create command. The code in azuresite/production.py automatically appends .postgres.database.azure.com to create the full PostgreSQL server URL.
DBNAME → Use restaurant.
DBUSER, DBPASS → Use the administrator credentials that you used with the earlier az postgres flexible-server create command. The code in azuresite/production.py automatically constructs the full Postgres username from DBUSER and DBHOST, so don't include the @server portion.
Azure App service supports multiple methods to deploy your application code to Azure including support for GitHub Actions and all major CI/CD tools. This article focuses on how to deploy your code from your local workstation to Azure.
To deploy a web app from VS Code, you must have the Azure Tools extension pack installed and be signed into Azure from VS Code.
Instructions
Screenshot
Locate the Azure icon in the left-hand toolbar and select it to bring up the Azure Tools for VS Code extension.
In the Azure Tools extension:
Expand RESOURCES. (Make sure resources are sorted by resource type.)
Right-click your web app to bring up the context menu.
Select Deploy to Web App... from the menu.
Select your web app as the web app to deploy in the dialog at the top of the screen.
Select Deploy in the dialog box.
Select Yes to update your build configuration and improve deployment performance.
When the deployment is complete, a dialog box will appear in the lower right corner of the screen with an option to browse to the website. If you use this link, the web page will report an error because the web app isn't ready until you do the migration in the next step. You may see another dialog box warning of this problem.
You can deploy your application code from a local Git repository to Azure by configuring a Git remote in your local repo pointing at Azure to push code to. The URL of the remote repository and Git credentials needed for configuration can be retrieved using either the Azure portal or the Azure CLI.
Enter the name of your App Service in the search box at the top of the screen.
The App Service will appear under the Resources heading. Select the App Service to navigate to it.
Go to the page for the App Service.
Select Deployment Center from the menu on the left side of the screen.
In the dropdown list labeled Source, select Local Git.
Select Save from the top menu bar.
After saving, the page will refresh and display the address for the remote Git repository.
Copy the value of the Git Clone Uri as this value will be used to set up a Git remote in a later step.
Go to the Deployment Center page.
Navigate to the Local Git/FTPS credentials tab.
Locate the username and password under the Application Scope credentials.
Keep this screen open so you can copy these credentials momentarily when you deploy your code to the remote repository.
When you push code to the remote Git repository for the first time, these credentials are needed to authenticate to the remote repository.
First, you need to tell Azure what branch to use for deployment. This value is stored in the app settings for the web app with a key of DEPLOYMENT_BRANCH. For this example, you will be deploying code from the main branch.
az webapp config appsettings set \
--name $APP_SERVICE_NAME \
--resource-group $RESOURCE_GROUP_NAME \
--settings DEPLOYMENT_BRANCH='main'
az webapp config appsettings set `
--name $APP_SERVICE_NAME `
--resource-group $RESOURCE_GROUP_NAME `
--settings DEPLOYMENT_BRANCH='main'
Next, configure the deployment source for your web app to be local Git using the az webapp deployment source command. This command will output the URL of the remote Git repository that you will be pushing code to. Make a copy of this value as you will need it in a later step.
Retrieve the deployment credentials for your application. These will be needed for Git to authenticate to Azure when you push code to Azure in a later step.
Next, in the root directory of your application, configure a Git remote that points to Azure using the Git URL of the Azure remote obtained in a previous step.
git remote add azure <git-deployment-url>
You can now push code from your local Git repository to Azure using the Git remote you configured.
git push azure main:master
The first time you push code to Azure, Git will prompt you for the Azure deployment credentials you obtained in a previous step. Git will then cache these credentials so you won't have to enter them on subsequent deployments.
Applications can be deployed to Azure by creating and uploading a ZIP file of the application code to Azure. ZIP files can be uploaded to Azure using the Azure CLI or a HTTP client like cURL.
Enable build automation
When deploying a ZIP file of your Python code, you need to set a flag to enable Azure's build automation. The build automation will install any necessary requirements and package the application to run on Azure.
Build automation in Azure is enabled by setting the SCM_DO_BUILD_DURING_DEPLOYMENT app setting in either the Azure portal or Azure CLI.
az webapp config appsettings set \
--resource-group $RESOURCE_GROUP_NAME \
--name $APP_SERVICE_NAME \
--settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
az webapp config appsettings set `
--resource-group $RESOURCE_GROUP_NAME `
--name $APP_SERVICE_NAME `
--settings SCM_DO_BUILD_DURING_DEPLOYMENT=true
Create a ZIP file of your application
Next, create a ZIP file of your application. You only need to include components of the application itself. You do not need to include any files or directories that start with a dot (.) such as .venv, .gitignore, .github, or .vscode.
az webapp deploy \
--name $APP_SERVICE_NAME \
--resource-group $RESOURCE_GROUP_NAME \
--src-path <zip-file-path> \
--type zip
az webapp deploy `
--name $APP_SERVICE_NAME `
--resource-group $RESOURCE_GROUP_NAME `
--src-path <zip-file-path> `
--type zip
To use an HTTP client such as cURL to upload your ZIP file to Azure, you need the deployment username and password for your App Service. These credentials can be obtained from the Azure portal.
On the page for the web app, select Deployment center from the resource menu on the left side of the page.
Select the FTPS credentials tab.
The Username and Password are shown under the Application scope heading. For ZIP file deployments, only use the part of the username after the \ character that starts with a $, for example $msdocs-python-django-webapp-123. These credentials will be needed in the cURL command below.
Run the following curl command to upload your zip file to Azure and deploy your application. The username is the deployment username obtained above. When this command is run, you will be prompted for the deployment password.
With the code deployed and the database in place, the app is almost ready to use. First, you need to establish the necessary schema in the database itself. You do this by "migrating" the data models in the Django app to the database.
Step 1. Create SSH session and connect to web app server.
az webapp ssh --resource-group $RESOURCE_GROUP_NAME \
--name $APP_SERVICE_NAME
az webapp ssh --resource-group $RESOURCE_GROUP_NAME `
--name $APP_SERVICE_NAME
Note
If you cannot connect to the SSH session, then the app itself has failed to start. Check the diagnostic logs for details. For example, if you haven't created the necessary app settings in the previous section, the logs will indicate KeyError: 'DBNAME'.
Step 2. In the SSH session, run the following command to migrate the models into the database schema (you can paste commands using Ctrl+Shift+V):
When you deploy the Flask sample app to Azure App Service, the database tables are created automatically in Azure PostgreSQL. If the tables aren't created, try the following command:
# Create database tables
flask db init
# Create database tables
python manage.py migrate
If you encounter any errors related to connecting to the database, check the values of the application settings of the App Service created in the previous section, namely DBHOST, DBNAME, DBUSER, and DBPASS. Without those settings, the migrate command can't communicate with the database.
Tip
In an SSH session, for Django you can also create users with the python manage.py createsuperuser command like you would with a typical Django app. For more information, see the documentation for django django-admin and manage.py. Use the superuser account to access the /admin portion of the web site. For Flask, use an extension such as Flask-admin to provide the same functionality.
Browse to the deployed application in your web browser at the URL http://<app-name>.azurewebsites.net. It can take a minute or two for the app to start, so if you see a default app page, wait a minute and refresh the browser.
When you see your sample web app, it's running in a Linux container in App Service using a built-in image Congratulations! You've deployed your Python app to App Service.
Azure App Service captures all messages output to the console to help you diagnose issues with your application. The sample app includes print() statements to demonstrate this capability as shown below.
First, you need to enable streaming logs in Azure App Service. Navigate to page for the App Service instance in the Azure portal.
Select the App Service logs under the Monitoring heading in the menu on the left side of the page.
Change the Application Logging property from Off to File System.
Enter a retention period of 30 days for the logs.
Select Save to save your changes.
Select the Log stream item from the menu under the Monitoring section. Refresh the home page in the app or attempt other requests to generate some log messages.
You will see any log messages generated by your app and messages generated by the service in the output.
Instructions
Screenshot
First, you need to enable streaming logs in Azure App Service.
In the App Service section of the Azure Tools for VS Code extension, right-click on your App Service instance and select Start Streaming Logs from the menu.
The console logs appear in VS Code's Output window. Refresh the home page in the app or attempt other requests to generate some log messages.
You'll see any log messages generated by your app and other messages generated by the service in the output.
Run the following Azure CLI commands to see the log stream. This command uses parameters cached in the .azure/config file.
Step 1. Configure Azure App Service to output logs to the App Service filesystem using the az webapp log config command.
You can leave the app and database running as long as you want for further development work and skip ahead to Next steps.
However, when you're finished with the sample app, you can remove all of the resources for the app from Azure to ensure you don't incur other charges and keep your Azure subscription uncluttered. Removing the resource group also removes all resources in the resource group and is the fastest way to remove all Azure resources for your app.