You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/service-connector/tutorial-django-webapp-postgres-cli.md
+13-15Lines changed: 13 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ author: maud-lv
6
6
ms.author: malev
7
7
ms.service: service-connector
8
8
ms.topic: how-to
9
-
ms.date: 04/14/2026
9
+
ms.date: 04/15/2026
10
10
ms.custom:
11
11
- devx-track-azurecli
12
12
- devx-track-python
@@ -45,7 +45,7 @@ You use Azure CLI to complete the following tasks:
45
45
46
46
1. Make sure your subscription is registered to use the `Microsoft.ServiceLinker` and `Microsoft.DBforPostgreSQL` resource providers. If not, run `az provider register -n Microsoft.[name of service]` to register the providers.
47
47
48
-
1. Install the following needed Azure CLI extensions:
48
+
1. Install the following Azure CLI extensions:
49
49
50
50
```azurecli
51
51
az extension add --name serviceconnector-passwordless --upgrade
@@ -128,13 +128,11 @@ In the code, the `sku` defines the CPU, memory, and cost of the App Service plan
128
128
129
129
## Create the Postgres database in Azure
130
130
131
-
Create the Azure Database for PostgreSQL database to store the app information. The [az postgres flexible-server create](/cli/azure/postgres/flexible-server#az-postgres-flexible-server-create) commandperforms the following actions, which take a few minutes:
131
+
Create the Azure Database forPostgreSQL database to store app information. The [az postgres flexible-server create](/cli/azure/postgres/flexible-server#az-postgres-flexible-server-create) command creates an Azure Database for PostgreSQL flexible serverin the specified resource group that has:
132
132
133
-
* Creates an Azure Database forPostgreSQL flexible serverin the specified resource group that has:
134
-
* Server name specified in the `--name` parameter. The name must be unique across all of Azure.
135
-
* SKU specified in the `--sku-name` parameter.
136
-
* Administrator account username and password specified in the `--admin-user` and `--admin-password` parameters.
137
-
* Creates a database in the server with database name specified in the `--database-name` parameter.
133
+
* Server name specified in the `--name` parameter. The name must be unique across all of Azure.
134
+
* SKU specified in the `--sku-name` parameter.
135
+
* Administrator account username and password specified in the `--admin-user` and `--admin-password` parameters.
138
136
139
137
1. Create the Azure Database for PostgreSQL server. If prompted to enable access to the current client IP address, enter `y`for yes.
140
138
@@ -149,7 +147,7 @@ Create the Azure Database for PostgreSQL database to store the app information.
149
147
--microsoft-entra-auth Enabled
150
148
```
151
149
152
-
1. If not prompted to enable access to your current client IP address, configure a firewall rule on your server with the [az postgres flexible-server firewall-rule create](/cli/azure/postgres/flexible-server/firewall-rule) command. This rule allows your local environment access to the server.
150
+
1. If you weren't prompted to enable access to your current client IP address, configure a firewall rule on your server with the [az postgres flexible-server firewall-rule create](/cli/azure/postgres/flexible-server/firewall-rule) command. This rule allows your local environment access to the server.
153
151
154
152
```azurecli
155
153
IP_ADDRESS=<your IP address>
@@ -179,7 +177,7 @@ Create the Azure Database for PostgreSQL database to store the app information.
179
177
180
178
Use [az webapp connection create postgres-flexible](/cli/azure/webapp/connection/create#az-webapp-connection-create-postgres-flexible) to add a service connector that connects the Azure web app to the Postgres database using passwordless managed identity authentication. The following command configures Azure Database for PostgreSQL to use managed identity and Azure role-based access control. The command output lists the actions Service Connector takes.
181
179
182
-
The command creates creates an environment variable named `AZURE_POSTGRESQL_CONNECTIONSTRING` that provides the database connection information for the app. The app code accesses app environment variables with statements like `os.environ.get('AZURE_POSTGRESQL_HOST')`. For more information, see [Access environment variables](/azure/app-service/configure-language-python#access-environment-variables).
180
+
The command creates an environment variable named `AZURE_POSTGRESQL_CONNECTIONSTRING` that provides the database connection information for the app. The app code accesses app environment variables with statements like `os.environ.get('AZURE_POSTGRESQL_HOST')`. For more information, see [Access environment variables](/azure/app-service/configure-language-python#access-environment-variables).
183
181
184
182
```azurecli
185
183
az webapp connection create postgres-flexible \
@@ -215,7 +213,7 @@ Use [az webapp connection create storage-blob](/cli/azure/webapp/connection/crea
1. Update the storage account to allow blob public access for the app users to access images.
216
+
1. Update the storage account to allow blob public access for app users to access photos.
219
217
220
218
```azurecli
221
219
az storage account update \
@@ -241,17 +239,17 @@ Use [az webapp connection create storage-blob](/cli/azure/webapp/connection/crea
241
239
242
240
## Test the Python web app in Azure
243
241
244
-
The app uses the [azure.identity](https://pypi.org/project/azure-identity/) package and its `DefaultAzureCredential` class. When the app is running in Azure, The`DefaultAzureCredential` automatically detects when a managed identity exists for the App Service, and uses it to access the Azure Storage and Azure Database for PostgreSQL resources. You don't need to provide storage keys, certificates, or credentials to App Service to access these resources.
242
+
The app uses the [azure.identity](https://pypi.org/project/azure-identity/) package and its `DefaultAzureCredential` class. When the app is running in Azure, the`DefaultAzureCredential` automatically detects when a managed identity exists for the App Service, and uses it to access the Azure Storage and Azure Database for PostgreSQL resources. You don't need to provide storage keys, certificates, or credentials to App Service to access these resources.
245
243
246
-
1. Browse to the deployed application at the URL `https://$APP_SERVICE_NAME.azurewebsites.net`, or by selecting the **Default domain** link on the Azure portal app page. It can take a minute or two for the app to start. If you see a default app page that isn't the sample app, wait a minute and refresh the browser.
244
+
1. Browse to the deployed application at the URL `https://$APP_SERVICE_NAME.azurewebsites.net`. It can take a minute or two for the app to start. If you see a default app page that isn't the sample app, wait a minute and refresh the browser.
247
245
248
246
1. Test the functionality of the sample app by adding a restaurant and some reviews with photos for the restaurant. The app should resemble the following screenshot:
249
247
250
248
:::image type="content" source="media/tutorial-django-webapp-postgres-cli/example-of-review-sample-app-production-deployed-small.png" lightbox="media/tutorial-django-webapp-postgres-cli/example-of-review-sample-app-production-deployed.png" alt-text="Screenshot of the sample app showing restaurant review functionality using App Service, Azure Database for PostgreSQL, and Azure Storage." :::
251
249
252
250
## Clean up resources
253
251
254
-
If you don't want to keep the app or resources you created for this tutorial, you can delete the resource group that contains the resources to avoid ongoing charges. Be sure you no longer need the resources before using the command.
252
+
To avoid ongoing charges, you can delete the resource group that contains the resources you created for this tutorial. Be sure you no longer need the app or the resources before running the command.
255
253
256
254
```azurecli
257
255
az group delete --name $RESOURCE_GROUP_NAME --no-wait
@@ -261,7 +259,7 @@ Deleting all the resources can take some time. The `--no-wait` argument allows t
261
259
262
260
## Troubleshooting
263
261
264
-
If you have issues with this tutorial, see the following resources:
262
+
If you have issues running this tutorial, see the following resources:
265
263
266
264
- [Troubleshoot Linux Python apps for Azure App Service](/azure/app-service/configure-language-python#troubleshooting)
0 commit comments