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/containers/tutorial-python-postgresql-app.md
+12-19Lines changed: 12 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,11 +49,7 @@ In a local terminal window, run `psql` to connect to your local PostgreSQL serve
49
49
psql -U postgres
50
50
```
51
51
52
-
If the connection isn't successful, make sure your PostgreSQL server is running, or restart it if necessary by running a command like:
53
-
54
-
```bash
55
-
pg_ctl.exe restart -D "<postgresql data directory>"
56
-
```
52
+
If the connection isn't successful, make sure your PostgreSQL server is running, or restart it if necessary.
57
53
58
54
Create a new database called *pollsdb*, and set up a database user named *manager* with password *supersecretpass*:
59
55
@@ -66,7 +62,6 @@ GRANT ALL PRIVILEGES ON DATABASE pollsdb TO manager;
66
62
Type `\q` to exit the PostgreSQL client.
67
63
68
64
<aname="step2"></a>
69
-
70
65
## Create and run the Python app
71
66
72
67
Next, set up and run the sample Python Django web app.
@@ -96,7 +91,7 @@ py -3 -m venv venv
96
91
venv\scripts\activate
97
92
```
98
93
99
-
In the `venv` environment, run *env.sh* or *env.ps1* to set the environment variables *azuresite/settings.py* will use for the database connection settings.
94
+
In the `venv` environment, run *env.sh* or *env.ps1* to set the environment variables that *azuresite/settings.py* will use for the database connection settings.
100
95
101
96
```bash
102
97
source ./env.sh
@@ -167,16 +162,13 @@ You create a PostgreSQL server with the [az postgres server create](/cli/azure/p
167
162
168
163
In the following command, replace *\<postgresql-name>* with a unique server name. The server name is part of your PostgreSQL endpoint *https://\<postgresql-name>.postgres.database.azure.com*, so the name needs to be unique across all servers in Azure.
169
164
170
-
Replace *\<resourcegroup-name>* and *\<region>* with the name and region of the resource group you want to use. Replace *\<admin-username>* and *\<admin-password>* with user credentials for the database administrator account.
171
-
172
-
> [!NOTE]
173
-
> Remember the *\<admin-username>* and *\<admin-password>* to use later for signing in to the PostgreSQL server and databases.
165
+
Replace *\<resourcegroup-name>* and *\<region>* with the name and region of the resource group you want to use. For *\<admin-username>* and *\<admin-password>*, create user credentials for the database administrator account. Remember the *\<admin-username>* and *\<admin-password>* to use later for signing in to the PostgreSQL server and databases.
174
166
175
167
```azurecli-interactive
176
168
az postgres server create --resource-group <resourcegroup-name> --name <postgresql-name> --location "<region>" --admin-user <admin-username> --admin-password <admin-password> --sku-name B_Gen4_1
177
169
```
178
170
179
-
After the Azure Database for PostgreSQL server is created, the Azure CLI returns JSON code like the following example:
171
+
When the Azure Database for PostgreSQL server is created, the Azure CLI returns JSON code like the following example:
180
172
181
173
```json
182
174
{
@@ -216,7 +208,7 @@ az postgres server firewall-rule create --resource-group <resourcegroup-name> --
216
208
217
209
### Create and connect to the Azure Database for PostgreSQL database
218
210
219
-
Connect to your Azure Database for PostgreSQL server by running the following command. Use your own *\<postgresql-name>* and *\<admin-username>*, and sign in with the password you created for the server.
211
+
Connect to your Azure Database for PostgreSQL server by running the following command. Use your own *\<postgresql-name>* and *\<admin-username>*, and sign in with the password you created.
@@ -232,9 +224,10 @@ GRANT ALL PRIVILEGES ON DATABASE pollsdb TO manager;
232
224
233
225
> [!NOTE]
234
226
> It's a best practice to create database users with restricted permissions for specific apps, instead of using the admin user. The `manager` user has full privileges to *only* the `pollsdb` database.
227
+
235
228
Type `\q` to exit the PostgreSQL client.
236
229
237
-
### Test app connectivity to the Azure Database for PostgreSQL production database
230
+
### Test app connectivity to the Azure PostgreSQL database
238
231
239
232
Edit your local *env.sh* or *env.ps1* file to point to to your cloud PostgreSQL database, by replacing *\<postgresql-name>* with your Azure Database for PostgreSQL server name.
240
233
@@ -252,7 +245,7 @@ $Env:DBNAME = "pollsdb"
252
245
$Env:DBPASS = "supersecretpass"
253
246
```
254
247
255
-
In the `venv` environment in your local terminal window, run *env.sh* or *env.ps1* again.
248
+
In the `venv` environment in your local terminal window, run the edited *env.sh* or *env.ps1*.
256
249
```bash
257
250
source ./env.sh
258
251
```
@@ -298,7 +291,7 @@ You need to change and add some settings in your *djangoapp/azuresite/settings.p
1. Django doesn't support [serving static files in production](https://docs.djangoproject.com/en/2.1/howto/static-files/deployment/). For this tutorial, you use [WhiteNoise](https://whitenoise.evans.io/en/stable/) to enable serving the needed files. The WhiteNoise package was already installed with *requirements.txt*.
294
+
1. Django doesn't support [serving static files in production](https://docs.djangoproject.com/en/2.1/howto/static-files/deployment/). For this tutorial, you use [WhiteNoise](https://whitenoise.evans.io/en/stable/) to enable serving the files. The WhiteNoise package was already installed with *requirements.txt*.
302
295
303
296
To configure Django to use WhiteNoise, in *azuresite/settings.py*, find the `MIDDLEWARE` setting, and add `whitenoise.middleware.WhiteNoiseMiddleware` to the list, just after the `django.middleware.security.SecurityMiddleware` line. Your `MIDDLEWARE` setting should look like this:
Earlier in the tutorial, you defined environment variables to connect to your PostgreSQL database.
346
339
347
-
In Azure App Service, you set environment variables as *app settings* by using the [az webapp config appsettings set](/cli/azure/webapp/config/appsettings?view=azure-cli-latest#az-webapp-config-appsettings-set) command.
340
+
In Azure App Service, you set environment variables as *app settings*, by using the [az webapp config appsettings set](/cli/azure/webapp/config/appsettings?view=azure-cli-latest#az-webapp-config-appsettings-set) command.
348
341
349
342
In the Azure Cloud Shell, run the following command to specify the database connection details as app settings. Replace *\<app-name>*, *\<resourcegroup-name>*, and *\<postgresql-name>* with your own values.
350
343
@@ -384,13 +377,13 @@ The App Service deployment server sees *requirements.txt* in the repository root
384
377
385
378
### Browse to the Azure app
386
379
387
-
Browse to the deployed app with URL *https:\//\<app-name>.azurewebsites.net*. It takes some time to start, because the container must be downloaded and run when the app is requested for the first time. If the page times out or displays an error message, wait a few minutes and refresh the page.
380
+
Browse to the deployed app with URL *http:\//\<app-name>.azurewebsites.net*. It takes some time to start, because the container must be downloaded and run when the app is requested for the first time. If the page times out or displays an error message, wait a few minutes and refresh the page.
388
381
389
382
You should see the poll questions that you created earlier.
390
383
391
384
App Service detects a Django project in your repository by looking for a *wsgi.py* file in each subdirectory, which `manage.py startproject` creates by default. When App Service finds the file, it loads the Django web app. For more information on how App Service loads Python apps, see [Configure built-in Python image](how-to-configure-python.md).
392
385
393
-
Go to *https:\//\<app-name>.azurewebsites.net/admin* and sign in using the admin user you created. If you like, create some more poll questions.
386
+
Go to *http:\//\<app-name>.azurewebsites.net/admin* and sign in using the admin user you created. If you like, create some more poll questions.
394
387
395
388

0 commit comments