Skip to content

Commit b207d2e

Browse files
committed
Update article
1 parent cda3163 commit b207d2e

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed
-22.8 KB
Loading

articles/app-service/tutorial-python-postgresql-app.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To run the application locally, make sure you have [Python 3.7 or higher](https:
2727
### [Flask](#tab/flask)
2828

2929
```bash
30-
git clone https://github.com/Azure-Samples/msdocs-flask-postgresql-sample-app
30+
git clone https://github.com/Azure-Samples/msdocs-flask-postgresql-sample-app.git
3131
```
3232

3333
### [Django](#tab/django)
@@ -41,15 +41,22 @@ git clone https://github.com/Azure-Samples/msdocs-django-postgresql-sample-app.g
4141

4242
Go to the application folder:
4343

44+
### [Flask](#tab/flask)
45+
4446
```bash
45-
cd msdocs-python-flask-webapp-quickstart
47+
cd msdocs-flask-postgresql-sample-app
4648
```
4749

50+
### [Django](#tab/django)
51+
52+
```bash
53+
cd msdocs-django-postgresql-sample-app
54+
```
4855

49-
Create an *.env* file as shown below 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. Set the values of `DBHOST`, `DBUSER`, and `DBPASS` as appropriate for your local PostgreSQL instance. The `FLASK_DEBUG` environment variable is optional and used to enable debug mode in Flask.
56+
57+
Create an *.env* file as shown below 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. Set the values of `DBHOST`, `DBUSER`, and `DBPASS` as appropriate for your local PostgreSQL instance.
5058

5159
```
52-
FLASK_DEBUG=True
5360
DBNAME=<database name>
5461
DBHOST=<database-hostname>
5562
DBUSER=<db-user-name>
@@ -117,7 +124,7 @@ Sign in to the [Azure portal](https://portal.azure.com/) and follow these steps
117124
1. *Resource Group* &rarr; Select **Create new** and use a name of **msdocs-python-postgres-tutorial**.
118125
1. *Region* &rarr; Any Azure region near you.
119126
1. *Name* &rarr; **msdocs-python-postgres-XYZ** where *XYZ* is any three random characters. This name must be unique across Azure.
120-
1. *Runtime stack* &rarr; **Python 3.9**.
127+
1. *Runtime stack* &rarr; **Python 3.10**.
121128
1. *Database* &rarr; **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.
122129
1. *Hosting plan* &rarr; **Basic**. When you're ready, you can [scale up](manage-scale-up.md) to a production pricing tier later.
123130
1. Select **Review + create**.
@@ -158,8 +165,10 @@ The creation wizard generated the connectivity variables for you already as [app
158165
:::row-end:::
159166
:::row:::
160167
:::column span="2":::
161-
**Step 2.** In the **Application settings** tab of the **Configuration** page, verify that `DBNAME`, `DBHOST`, `DBUSER`, and `DBPASS` are present. They'll be injected into the runtime environment as environment variables.
162-
App settings are a good way to keep connection secrets out of your code repository.
168+
**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.
169+
App settings are one way to keep connection secrets out of your code repository.
170+
When you're ready to move your secrets to a more secure location,
171+
here's an [article on storing in Azure Key Vault](/azure/key-vault/certificates/quick-create-python).
163172
:::column-end:::
164173
:::column:::
165174
:::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":::
@@ -391,7 +400,7 @@ Having issues? [Let us know](https://aka.ms/DjangoCLITutorialHelp).
391400
:::row:::
392401
:::column span="2":::
393402
**Step 2.** Add a few restaurants to the list.
394-
Congratulations, you're running a secure data-driven Flask app in Azure App Service, with connectivity to Azure Database for PostgreSQL.
403+
Congratulations, you're running a web app in Azure App Service, with secure connectivity to Azure Database for PostgreSQL.
395404
:::column-end:::
396405
:::column:::
397406
:::image type="content" source="./media/tutorial-python-postgresql-app/azure-portal-browse-app-2.png" alt-text="A screenshot of the Flask web app with PostgreSQL running in Azure showing restaurants and restaurant reviews." lightbox="./media/tutorial-python-postgresql-app/azure-portal-browse-app-2.png":::
@@ -406,11 +415,15 @@ Azure App Service captures all messages output to the console to help you diagno
406415

407416
### [Flask](#tab/flask)
408417

409-
:::code language="python" source="~/msdocs-django-postgresql-sample-app/restaurant_review/views.py" range="12-16" highlight="2":::
418+
:::code language="python" source="~/msdocs-flask-postgresql-sample-app/app.py" range="37-41" highlight="3":::
419+
420+
For more robust logging, consider using Flask's [built-in logger](https://flask.palletsprojects.com/en/2.2.x/logging/).
410421

411422
### [Django](#tab/django)
412423

413-
:::code language="python" source="~/msdocs-flask-postgresql-sample-app/app.py" range="39-43" highlight="3":::
424+
:::code language="python" source="~/msdocs-django-postgresql-sample-app/restaurant_review/views.py" range="12-16" highlight="2":::
425+
426+
For more robust logging, consider using Django's [built-in logger](https://docs.djangoproject.com/en/4.1/topics/logging/).
414427

415428
-----
416429

@@ -528,11 +541,11 @@ For more information, see [Production settings for Django apps](configure-langua
528541

529542
#### I can't connect to the SSH session
530543

531-
If you can't connect to the SSH session, then the app itself has failed to start. Check the [diagnostic logs](#6-stream-diagnostic-logs) for details. For example, if you see an error like `KeyError: 'DBNAME'`, it may mean that the environment variable is missing (you may have removed the app setting).
544+
If you can't connect to the SSH session, then the app itself has failed to start. Check the [diagnostic logs](#6-stream-diagnostic-logs) for details. For example, if you see an error like `KeyError: 'AZURE_POSTGRESQL_CONNECTIONSTRING'`, it may mean that the environment variable is missing (you may have removed the app setting).
532545

533546
#### I get an error when running database migrations
534547

535-
If you encounter any errors related to connecting to the database, check if the app settings (`DBHOST`, `DBNAME`, `DBUSER`, and `DBPASS`) have been changed. Without those settings, the migrate command can't communicate with the database.
548+
If you encounter any errors related to connecting to the database, check if the app settings (`AZURE_POSTGRESQL_CONNECTIONSTRING`) have been changed. Without that connection string, the migrate command can't communicate with the database.
536549

537550
## Next steps
538551

0 commit comments

Comments
 (0)