Skip to content

Commit 9ff4569

Browse files
committed
changes
1 parent 202d9a6 commit 9ff4569

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

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

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ In a local terminal window, run `psql` to connect to your local PostgreSQL serve
4949
psql -U postgres
5050
```
5151

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.
5753

5854
Create a new database called *pollsdb*, and set up a database user named *manager* with password *supersecretpass*:
5955

@@ -66,7 +62,6 @@ GRANT ALL PRIVILEGES ON DATABASE pollsdb TO manager;
6662
Type `\q` to exit the PostgreSQL client.
6763

6864
<a name="step2"></a>
69-
7065
## Create and run the Python app
7166

7267
Next, set up and run the sample Python Django web app.
@@ -96,7 +91,7 @@ py -3 -m venv venv
9691
venv\scripts\activate
9792
```
9893

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.
10095

10196
```bash
10297
source ./env.sh
@@ -167,16 +162,13 @@ You create a PostgreSQL server with the [az postgres server create](/cli/azure/p
167162
168163
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.
169164

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.
174166

175167
```azurecli-interactive
176168
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
177169
```
178170

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:
180172

181173
```json
182174
{
@@ -216,7 +208,7 @@ az postgres server firewall-rule create --resource-group <resourcegroup-name> --
216208

217209
### Create and connect to the Azure Database for PostgreSQL database
218210

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.
220212

221213
```bash
222214
psql -h <postgresql-name>.postgres.database.azure.com -U <admin-username>@<postgresql-name> postgres
@@ -232,9 +224,10 @@ GRANT ALL PRIVILEGES ON DATABASE pollsdb TO manager;
232224

233225
> [!NOTE]
234226
> 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+
235228
Type `\q` to exit the PostgreSQL client.
236229

237-
### Test app connectivity to the Azure Database for PostgreSQL production database
230+
### Test app connectivity to the Azure PostgreSQL database
238231

239232
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.
240233

@@ -252,7 +245,7 @@ $Env:DBNAME = "pollsdb"
252245
$Env:DBPASS = "supersecretpass"
253246
```
254247

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*.
256249
```bash
257250
source ./env.sh
258251
```
@@ -298,7 +291,7 @@ You need to change and add some settings in your *djangoapp/azuresite/settings.p
298291
ALLOWED_HOSTS = [os.environ['WEBSITE_SITE_NAME'] + '.azurewebsites.net', '127.0.0.1'] if 'WEBSITE_SITE_NAME' in os.environ else []
299292
```
300293

301-
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*.
302295

303296
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:
304297

@@ -344,7 +337,7 @@ git commit -am "configure for App Service"
344337

345338
Earlier in the tutorial, you defined environment variables to connect to your PostgreSQL database.
346339

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.
348341

349342
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.
350343

@@ -384,13 +377,13 @@ The App Service deployment server sees *requirements.txt* in the repository root
384377

385378
### Browse to the Azure app
386379

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.
388381

389382
You should see the poll questions that you created earlier.
390383

391384
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).
392385

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.
394387

395388
![Run Python Django app in App Services in Azure](./media/tutorial-python-postgresql-app/run-python-django-app-in-azure.png)
396389

0 commit comments

Comments
 (0)