Skip to content

Commit 46d8dec

Browse files
authored
Merge pull request #190947 from vmagelo/vmagelo/new-python-tutorial
New version of python with postgresql tutorial
2 parents a70a4e8 + 5615198 commit 46d8dec

File tree

229 files changed

+1977
-394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+1977
-394
lines changed

.openpublishing.publish.config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,18 @@
830830
"url": "https://github.com/Azure-Samples/msdocs-nodejs-mongodb-azure-sample-app",
831831
"branch": "main",
832832
"branch_mapping": {}
833+
},
834+
{
835+
"path_to_root": "msdocs-django-postgresql-sample-app",
836+
"url": "https://github.com/Azure-Samples/msdocs-django-postgresql-sample-app",
837+
"branch": "main",
838+
"branch_mapping": {}
839+
},
840+
{
841+
"path_to_root": "msdocs-flask-postgresql-sample-app",
842+
"url": "https://github.com/Azure-Samples/msdocs-flask-postgresql-sample-app",
843+
"branch": "main",
844+
"branch_mapping": {}
833845
}
834846
],
835847
"branch_target_mapping": {

articles/app-service/configure-language-python.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,19 @@ Existing web applications can be redeployed to Azure as follows:
100100
1. **Source repository**: Maintain your source code in a suitable repository like GitHub, which enables you to set up continuous deployment later in this process.
101101
1. Your *requirements.txt* file must be at the root of your repository for App Service to automatically install the necessary packages.
102102
103-
1. **Database**: If your app depends on a database, provision the necessary resources on Azure as well. See [Tutorial: Deploy a Django web app with PostgreSQL - create a database](tutorial-python-postgresql-app.md#3-create-postgres-database-in-azure) for an example.
103+
1. **Database**: If your app depends on a database, provision the necessary resources on Azure as well. See [Tutorial: Deploy a Django web app with PostgreSQL - create a database](tutorial-python-postgresql-app.md#3---create-the-postgresql-database-in-azure) for an example.
104104
105-
1. **App service resources**: Create a resource group, App Service Plan, and App Service web app to host your application. You can most easily do this by doing an initial deployment of your code through the Azure CLI command `az webapp up`, as shown on [Tutorial: Deploy a Django web app with PostgreSQL - deploy the code](tutorial-python-postgresql-app.md#4-deploy-the-code-to-azure-app-service). Replace the names of the resource group, App Service Plan, and the web app to be more suitable for your application.
105+
1. **App service resources**: Create a resource group, App Service Plan, and App Service web app to host your application. You can most easily do this by doing an initial deployment of your code through the Azure CLI command [`az webapp up`](/cli/azure/webapp?az-webapp-up). Or, you can create and deploy resources as shown in [Tutorial: Deploy a Django web app with PostgreSQL](tutorial-python-postgresql-app.md). Replace the names of the resource group, App Service Plan, and the web app to be more suitable for your application.
106106
107107
1. **Environment variables**: If your application requires any environment variables, create equivalent [App Service application settings](configure-common.md#configure-app-settings). These App Service settings appear to your code as environment variables, as described on [Access environment variables](#access-app-settings-as-environment-variables).
108-
- Database connections, for example, are often managed through such settings, as shown in [Tutorial: Deploy a Django web app with PostgreSQL - configure variables to connect the database](tutorial-python-postgresql-app.md#42-configure-environment-variables-to-connect-the-database).
108+
- Database connections, for example, are often managed through such settings, as shown in [Tutorial: Deploy a Django web app with PostgreSQL - configure variables to connect the database](tutorial-python-postgresql-app.md#5---connect-the-web-app-to-the-database).
109109
- See [Production settings for Django apps](#production-settings-for-django-apps) for specific settings for typical Django apps.
110110
111111
1. **App startup**: Review the section, [Container startup process](#container-startup-process) later in this article to understand how App Service attempts to run your app. App Service uses the Gunicorn web server by default, which must be able to find your app object or *wsgi.py* folder. If needed, you can [Customize the startup command](#customize-startup-command).
112112
113113
1. **Continuous deployment**: Set up continuous deployment, as described on [Continuous deployment to Azure App Service](deploy-continuous-deployment.md) if using Azure Pipelines or Kudu deployment, or [Deploy to App Service using GitHub Actions](./deploy-continuous-deployment.md) if using GitHub actions.
114114
115-
1. **Custom actions**: To perform actions within the App Service container that hosts your app, such as Django database migrations, you can [connect to the container through SSH](configure-linux-open-ssh-session.md). For an example of running Django database migrations, see [Tutorial: Deploy a Django web app with PostgreSQL - run database migrations](tutorial-python-postgresql-app.md#43-run-django-database-migrations).
115+
1. **Custom actions**: To perform actions within the App Service container that hosts your app, such as Django database migrations, you can [connect to the container through SSH](configure-linux-open-ssh-session.md). For an example of running Django database migrations, see [Tutorial: Deploy a Django web app with PostgreSQL - run database migrations](tutorial-python-postgresql-app.md#7---migrate-app-database).
116116
- When using continuous deployment, you can perform those actions using post-build commands as described earlier under [Customize build automation](#customize-build-automation).
117117
118118
With these steps completed, you should be able to commit changes to your source repository and have those updates automatically deployed to App Service.
@@ -415,7 +415,7 @@ When attempting to run database migrations with a Django app, you may see "sqlit
415415

416416
Check the `DATABASES` variable in the app's *settings.py* file to ensure that your app is using a cloud database instead of SQLite.
417417

418-
If you're encountering this error with the sample in [Tutorial: Deploy a Django web app with PostgreSQL](tutorial-python-postgresql-app.md), check that you completed the steps in [Configure environment variables to connect the database](tutorial-python-postgresql-app.md#42-configure-environment-variables-to-connect-the-database).
418+
If you're encountering this error with the sample in [Tutorial: Deploy a Django web app with PostgreSQL](tutorial-python-postgresql-app.md), check that you completed the steps in [Configure environment variables to connect the database](tutorial-python-postgresql-app.md#5---connect-the-web-app-to-the-database).
419419

420420
#### Other issues
421421

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
author: jess-johnson-msft
3+
ms.author: jejohn
4+
ms.topic: include
5+
ms.date: 01/25/2022
6+
ms.service: app-service
7+
ms.role: developer
8+
ms.devlang: python
9+
ms.azure.devx-azure-tooling: ['azure-portal']
10+
ms.custom: devx-track-python
11+
---
12+
13+
Create a rule that allows other Azure services to connect to the PostgreSQL server by using the [az postgres server firewall-rule create](/cli/azure/postgres/server/firewall-rule) command.
14+
15+
#### [bash](#tab/terminal-bash)
16+
17+
```azurecli
18+
az postgres server firewall-rule create --resource-group $RESOURCE_GROUP_NAME \
19+
--server $DB_SERVER_NAME \
20+
--name AllowAllWindowsAzureIps \
21+
--start-ip-address 0.0.0.0 \
22+
--end-ip-address 0.0.0.0
23+
```
24+
25+
#### [PowerShell terminal](#tab/terminal-powershell)
26+
27+
```azurecli
28+
az postgres server firewall-rule create --resource-group $RESOURCE_GROUP_NAME `
29+
--server $DB_SERVER_NAME `
30+
--name AllowAllWindowsAzureIps `
31+
--start-ip-address 0.0.0.0 `
32+
--end-ip-address 0.0.0.0
33+
```
34+
35+
---
36+
37+
* *resource-group* → Name of resource group from earlier in this tutorial. (`msdocs-python-postgres-webapp-rg`)
38+
* *server* → Name of the server from **Step 1**. (`msdocs-python-postgres-webapp-db`)
39+
* *name* → Name for firewall rule. (use `AllowAllWindowsAzureIps`)
40+
* *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](/azure/virtual-network/virtual-networks-overview).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
author: jess-johnson-msft
3+
ms.author: jejohn
4+
ms.topic: include
5+
ms.date: 01/25/2022
6+
ms.service: app-service
7+
ms.role: developer
8+
ms.devlang: python
9+
ms.azure.devx-azure-tooling: ['azure-portal']
10+
ms.custom: devx-track-python
11+
---
12+
13+
Add a rule to allow your web app to access the PostgreSQL Flexible server.
14+
15+
1. In the left resource page for the server, select **Networking**.
16+
17+
1. Select the checkbox next to **Allow public access from any Azure service within Azure to this server**.
18+
19+
1. Select **Save** to save the change.
20+
21+
To further secure communication between production web apps and database servers, you should use an
22+
[Azure Virtual Network](/azure/virtual-network/virtual-networks-overview).
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
author: jess-johnson-msft
3+
ms.author: jejohn
4+
ms.topic: include
5+
ms.date: 01/28/2022
6+
ms.service: app-service
7+
ms.role: developer
8+
ms.devlang: python
9+
ms.azure.devx-azure-tooling: ['vscode-azure-tools']
10+
ms.custom: devx-track-python
11+
---
12+
13+
Delete the resource group by using the [az group delete](/cli/azure/group#az_group_delete) command.
14+
15+
#### [bash](#tab/terminal-bash)
16+
17+
```azurecli
18+
az group delete \
19+
--name $RESOURCE_GROUP_NAME
20+
```
21+
22+
#### [PowerShell terminal](#tab/terminal-powershell)
23+
24+
```azurecli
25+
az group delete `
26+
--name $RESOURCE_GROUP_NAME
27+
```
28+
29+
---
30+
31+
You can optionally add the `--no-wait` argument to allow the command to return before the operation is complete.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
author: jess-johnson-msft
3+
ms.author: jejohn
4+
ms.topic: include
5+
ms.date: 01/25/2022
6+
ms.service: app-service
7+
ms.role: developer
8+
ms.devlang: python
9+
ms.azure.devx-azure-tooling: ['azure-portal']
10+
ms.custom: devx-track-python
11+
---
12+
13+
In the portal, go to the App Service page for the web app.
14+
15+
1. Select **Configuration** under **Settings** on the left side.
16+
17+
1. Select **Application settings** at the top of the page.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
author: jess-johnson-msft
3+
ms.author: jejohn
4+
ms.topic: include
5+
ms.date: 01/25/2022
6+
ms.service: app-service
7+
ms.role: developer
8+
ms.devlang: python
9+
ms.azure.devx-azure-tooling: ['azure-portal']
10+
ms.custom: devx-track-python
11+
---
12+
13+
Create application settings:
14+
15+
1. Select **+ New application setting** to create settings for each of the following values (which are expected by the django sample app):
16+
17+
* *DBHOST* &rarr; Use the server name you used earlier when created the database, for example, *msdocs-python-postgres-webapp-db-\<unique id>*.
18+
The code in azuresite/production.py automatically appends .postgres.database.azure.com to create the full PostgreSQL server URL.
19+
* *DBNAME* &rarr; Enter `restaurant`, the name of the application database.
20+
* *DBUSER* &rarr; The administrator user name used when you provisioned the database.
21+
* *DBPASS* &rarr; The administrator **secure password** you created earlier.
22+
23+
1. Confirm you have four settings and view their hidden values.
24+
25+
1. Select **Save** and to apply the settings.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
author: jess-johnson-msft
3+
ms.author: jejohn
4+
ms.topic: include
5+
ms.date: 01/25/2022
6+
ms.service: app-service
7+
ms.role: developer
8+
ms.devlang: python
9+
ms.azure.devx-azure-tooling: ['vscode-azure-tools']
10+
ms.custom: devx-track-python
11+
---
12+
13+
To set environment variables in App Service, you create *app settings* with the following [az webapp config appsettings set](/cli/azure/webapp/config/appsettings#az_webapp_config_appsettings_set) command.
14+
15+
#### [bash](#tab/terminal-bash)
16+
17+
```azurecli
18+
az webapp config appsettings set \
19+
--resource-group $RESOURCE_GROUP_NAME \
20+
--name $APP_SERVICE_NAME \
21+
--settings DBHOST=$DB_SERVER_NAME DBNAME=$DB_NAME DBUSER=$ADMIN_USERNAME DBPASS=$ADMIN_PWD
22+
```
23+
24+
#### [PowerShell terminal](#tab/terminal-powershell)
25+
26+
```azurecli
27+
az webapp config appsettings set `
28+
--resource-group $RESOURCE_GROUP_NAME `
29+
--name $APP_SERVICE_NAME `
30+
--settings DBHOST=$DB_SERVER_NAME DBNAME=$DB_NAME DBUSER=$ADMIN_USERNAME DBPASS=$ADMIN_PWD
31+
```
32+
33+
---
34+
35+
* *DBHOST* &rarr; 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.
36+
* *DBNAME* &rarr; Use `restaurant`.
37+
* *DBUSER, DBPASS* &rarr; 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.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
author: jess-johnson-msft
3+
ms.author: jejohn
4+
ms.topic: include
5+
ms.date: 01/25/2022
6+
ms.service: app-service
7+
ms.role: developer
8+
ms.devlang: python
9+
ms.azure.devx-azure-tooling: ['vscode-azure-tools']
10+
ms.custom: devx-track-python
11+
---
12+
13+
Locate the Azure icon in the left-hand toolbar and select it to bring up the Azure Tools for VS Code extension.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
author: jess-johnson-msft
3+
ms.author: jejohn
4+
ms.topic: include
5+
ms.date: 01/25/2022
6+
ms.service: app-service
7+
ms.role: developer
8+
ms.devlang: python
9+
ms.azure.devx-azure-tooling: ['vscode-azure-tools']
10+
ms.custom: devx-track-python
11+
---
12+
13+
In the **App Service** section of the Azure Tools extension:
14+
15+
1. Locate your web app, expand the node, and under **Application Settings** right-click to bring up the context menu.
16+
17+
1. Select **Add new setting...** from the menu.

0 commit comments

Comments
 (0)