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/app-service/tutorial-python-postgresql-app.md
+36-7Lines changed: 36 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,14 @@ DBUSER=<db-user-name>
66
66
DBPASS=<db-password>
67
67
```
68
68
69
+
Create a SECRET_KEY value for your app by running the following command at a terminal prompt: `python -c 'import secrets; print(secrets.token_hex())'`.
70
+
71
+
Set the returned value as the value of `SECRET_KEY` in the .env file.
@@ -128,7 +136,7 @@ Sign in to the [Azure portal](https://portal.azure.com/) and follow these steps
128
136
1. *Region*→ Any Azure region near you.
129
137
1. *Name*→**msdocs-python-postgres-XYZ** where *XYZ* is any three random characters. This name must be unique across Azure.
130
138
1. *Runtime stack*→**Python 3.10**.
131
-
1. *Database*→**PostgreSQL - Flexible Server** is selected by default as the database engine. The server name and database name is also set by default to appropriate values.
139
+
1. *Database*→**PostgreSQL - Flexible Server** is selected by default as the database engine. The server name and database name are also set by default to appropriate values.
132
140
1. *Hosting plan*→**Basic**. When you're ready, you can [scale up](manage-scale-up.md) to a production pricing tier later.
133
141
1. Select **Review + create**.
134
142
1. After validation completes, select **Create**.
@@ -154,7 +162,7 @@ Sign in to the [Azure portal](https://portal.azure.com/) and follow these steps
154
162
155
163
## 2. Verify connection settings
156
164
157
-
The creation wizard generated the connectivity variables for you already as [app settings](configure-common.md#configure-app-settings).
165
+
The creation wizard generated the connectivity variables for you already as [app settings](configure-common.md#configure-app-settings). App settings are one way to keep connection secrets out of your code repository. When you're ready to move your secrets to a more secure location, here's an [article on storing in Azure Key Vault](../key-vault/certificates/quick-create-python.md).
158
166
159
167
:::row:::
160
168
:::column span="2":::
@@ -167,14 +175,35 @@ The creation wizard generated the connectivity variables for you already as [app
167
175
:::row:::
168
176
:::column span="2":::
169
177
**Step 2.** In the **Application settings** tab of the **Configuration** page, verify that `AZURE_POSTGRESQL_CONNECTIONSTRING` is present. That will be injected into the runtime environment as an environment variable.
170
-
App settings are one way to keep connection secrets out of your code repository.
171
-
When you're ready to move your secrets to a more secure location,
172
-
here's an [article on storing in Azure Key Vault](../key-vault/certificates/quick-create-python.md).
173
178
:::column-end:::
174
179
:::column:::
175
180
:::image type="content" source="./media/tutorial-python-postgresql-app/azure-portal-get-connection-string-2.png" alt-text="A screenshot showing how to see the autogenerated connection string." lightbox="./media/tutorial-python-postgresql-app/azure-portal-get-connection-string-2.png":::
176
181
:::column-end:::
177
182
:::row-end:::
183
+
:::row:::
184
+
:::column span="2":::
185
+
**Step 3.** In a terminal or command prompt, run the following Python script to generate a unique secret: `python -c 'import secrets; print(secrets.token_hex())'`. Copy the output value to use in the next step.
186
+
:::column-end:::
187
+
:::column:::
188
+
:::column-end:::
189
+
:::row-end:::
190
+
:::row:::
191
+
:::column span="2":::
192
+
**Step 4.** In the **Application settings** tab of the **Configuration** page, select **New application setting**. Name the setting `SECRET_KEY`. Paste the value from the previous value. Select **OK**.
193
+
:::column-end:::
194
+
:::column:::
195
+
:::image type="content" source="./media/tutorial-python-postgresql-app/azure-portal-app-service-app-setting.png" alt-text="A screenshot showing how to set the SECRET_KEY app setting in the Azure portal." lightbox="./media/tutorial-python-postgresql-app/azure-portal-app-service-app-setting.png":::
196
+
:::column-end:::
197
+
:::row-end:::
198
+
:::row:::
199
+
:::column span="2":::
200
+
**Step 5.** Select **Save**.
201
+
:::column-end:::
202
+
:::column:::
203
+
:::image type="content" source="./media/tutorial-python-postgresql-app/azure-portal-app-service-app-setting-save.png" alt-text="A screenshot showing how to save the SECRET_KEY app setting in the Azure portal." lightbox="./media/tutorial-python-postgresql-app/azure-portal-app-service-app-setting-save.png":::
204
+
:::column-end:::
205
+
:::row-end:::
206
+
178
207
179
208
Having issues? Check the [Troubleshooting guide](configure-language-python.md#troubleshooting).
180
209
@@ -552,7 +581,7 @@ The `azd up` command cloned the sample app project template to your machine. The
552
581
553
582
* **Source code**: The code and assets for a Flask or Django web app that can be used for local development or deployed to Azure.
554
583
* **Bicep files**: Infrastructure as code (IaC) files that are used by `azd` to create the necessary resources in Azure.
555
-
* **Configuration files**: Essential configuration files such as `azure.yaml` that are used by `azd` to provision, deploy and wire resources together to produce a fully-fledged application.
584
+
* **Configuration files**: Essential configuration files such as `azure.yaml` that are used by `azd` to provision, deploy and wire resources together to produce a fullyfledged application.
556
585
557
586
### 2. Provisioned the Azure resources
558
587
@@ -563,7 +592,7 @@ The `azd up` command created all of the resources for the sample application in
563
592
* **Azure App Service plan**: An App Service plan was created to host App Service instances. App Service plans define what compute resources are available for one or more web apps.
564
593
* **Azure App Service**: An App Service instance was created in the new App Service plan to host and run the deployed application. In this case a Linux instance was created and configured to run Python apps. Additional configurations were also applied to the app service, such as setting the Postgres connection string and secret keys.
565
594
* **Azure Database for PostgresSQL**: A Postgres database and server were created for the app hosted on App Service to connect to. The required admin user, network and connection settings were also configured.
566
-
* **Azure Application Insights**: Application insights was setup and configured for the app hosted on the App Service. This service enables detailed telemetry and monitoring for your application.
595
+
* **Azure Application Insights**: Application insights was set up and configured for the app hosted on the App Service. This service enables detailed telemetry and monitoring for your application.
567
596
568
597
You can inspect the Bicep files in the [`infra`](https://github.com/Azure-Samples/msdocs-flask-postgresql-sample-app/tree/main/infra) folder of the project to understand how each of these resources were provisioned in more detail. The `resources.bicep` file defines most of the different services created in Azure. For example, the App Service plan and App Service web app instance were created and connected using the following Bicep code:
0 commit comments