Skip to content

Commit cfe69ce

Browse files
committed
Correct the tutorial Django articles so there isn't multiple include applies to references in them
1 parent e4220a8 commit cfe69ce

File tree

2 files changed

+27
-63
lines changed

2 files changed

+27
-63
lines changed

articles/postgresql/flexible-server/tutorial-django-aks-database.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ aks-nodepool1-31718369-0 Ready agent 6m44s v1.12.8
9595
```
9696

9797
## Create an Azure Database for PostgreSQL - Flexible Server
98+
9899
Create a flexible server with the [az postgreSQL flexible-server create](/cli/azure/postgres/flexible-server#az-postgres-flexible-server-create) command. The following command creates a server using service defaults and values from your Azure CLI's local context:
99100

100101
```azurecli-interactive
@@ -107,13 +108,11 @@ The server created has the below attributes:
107108
- Using public-access argument allow you to create a server with public access to any client with correct username and password.
108109
- Since the command is using local context it will create the server in the resource group ```django-project``` and in the region ```eastus```.
109110

110-
111111
## Build your Django docker image
112112

113113
Create a new [Django application](https://docs.djangoproject.com/en/3.1/intro/) or use your existing Django project. Make sure your code is in this folder structure.
114114

115-
116-
```
115+
```python
117116
└───my-djangoapp
118117
└───views.py
119118
└───models.py
@@ -130,8 +129,8 @@ Create a new [Django application](https://docs.djangoproject.com/en/3.1/intro/)
130129
└─── Dockerfile
131130
└─── requirements.txt
132131
└─── manage.py
133-
134132
```
133+
135134
Update ```ALLOWED_HOSTS``` in ```settings.py``` to make sure the Django application uses the external IP that gets assigned to kubernetes app.
136135

137136
```python
@@ -171,42 +170,35 @@ Create a new file named ```Dockerfile``` and copy the code snippet below. This D
171170
```docker
172171
# Use the official Python image from the Docker Hub
173172
174-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
175173
FROM python:3.8.2
176174
177175
# Make a new directory to put our code in.
178176
179-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
180177
RUN mkdir /code
181178
182179
# Change the working directory.
183180
184-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
185181
WORKDIR /code
186182
187183
# Copy to code folder
188184
189-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
190185
COPY . /code/
191186
192187
# Install the requirements.
193188
194-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
195189
RUN pip install -r requirements.txt
196190
197191
# Run the application:
198192
199-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
193+
200194
CMD python manage.py runserver 0.0.0.0:8000
201195
```
202196

203197
### Build your image
204198
Make sure you're in the directory ```my-django-app``` in a terminal using the ```cd``` command. Run the following command to build your bulletin board image:
205199

206-
``` bash
207-
200+
```bash
208201
docker build --tag myblog:latest .
209-
210202
```
211203

212204
Deploy your image to [Docker hub](https://docs.docker.com/get-started/part3/#create-a-docker-hub-repository-and-push-your-image) or [Azure Container registry](../../container-registry/container-registry-get-started-azure-cli.md).
@@ -217,7 +209,6 @@ Deploy your image to [Docker hub](https://docs.docker.com/get-started/part3/#cre
217209
>```azurecli-interactive
218210
>az aks update -n djangoappcluster -g django-project --attach-acr <your-acr-name>
219211
> ```
220-
>
221212
222213
## Create Kubernetes manifest file
223214
@@ -327,13 +318,14 @@ Now open a web browser to the external IP address of your service (http://\<serv
327318
328319
## Run database migrations
329320

330-
For any django application, you would need to run database migration or collect static files. You can run these django shell commands using ```$ kubectl exec <pod-name> -- [COMMAND]```. Before running the command you need to find the pod name using ```kubectl get pods```.
321+
For any django application, you would need to run database migration or collect static files. You can run these django shell commands using `$ kubectl exec <pod-name> -- [COMMAND]`. Before running the command you need to find the pod name using `kubectl get pods`.
331322

332323
```bash
333324
$ kubectl get pods
334325
```
335326

336-
You will see an output like this
327+
You will see an output like this:
328+
337329
```output
338330
NAME READY STATUS RESTARTS AGE
339331
django-app-5d9cd6cd8-l6x4b 1/1 Running 0 2m

articles/postgresql/flexible-server/tutorial-django-app-service-postgres.md

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ ms.custom: mvc, devx-track-azurecli
1616

1717
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
1818

19-
In this tutorial you will learn how to deploy a Django application in Azure using App Services and Azure Database for PostgreSQL - Flexible Server in a virtual network.
19+
In this tutorial you'll learn how to deploy a Django application in Azure using App Services and Azure Database for PostgreSQL - Flexible Server in a virtual network.
2020

2121
## Prerequisites
2222

2323
If you don't have an Azure subscription, create a [free](https://azure.microsoft.com/free/) account before you begin.
2424

2525
This article requires that you're running the Azure CLI version 2.0 or later locally. To see the version installed, run the `az --version` command. If you need to install or upgrade, see [Install Azure CLI](/cli/azure/install-azure-cli).
2626

27-
You'll need to login to your account using the [az login](/cli/azure/authenticate-azure-cli) command. Note the **id** property from the command output for the corresponding subscription name.
27+
You'll need to log in to your account using the [az login](/cli/azure/authenticate-azure-cli) command. Note the **id** property from the command output for the corresponding subscription name.
2828

2929
```azurecli
3030
az login
@@ -35,28 +35,25 @@ If you have multiple subscriptions, choose the appropriate subscription in which
3535
```azurecli
3636
az account set --subscription <subscription id>
3737
```
38+
3839
## Clone or download the sample app
3940

4041
# [Git clone](#tab/clone)
4142

42-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
43-
4443
Clone the sample repository:
4544

46-
```terminal
45+
```console
4746
git clone https://github.com/Azure-Samples/djangoapp
4847
```
4948

5049
Then go into that folder:
5150

52-
```terminal
51+
```console
5352
cd djangoapp
5453
```
5554

5655
# [Download](#tab/download)
5756

58-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
59-
6057
Visit [https://github.com/Azure-Samples/djangoapp](https://github.com/Azure-Samples/djangoapp), select **Clone**, and then select **Download ZIP**.
6158

6259
Unpack the ZIP file into a folder named *djangoapp*.
@@ -77,61 +74,49 @@ These changes are specific to configuring Django to run in any production enviro
7774
## Create a PostgreSQL Flexible Server in a new virtual network
7875

7976
Create a private flexible server and a database inside a virtual network (VNET) using the following command:
77+
8078
```azurecli
8179
# Create Flexible server in a VNET
8280
83-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
84-
8581
az postgres flexible-server create --resource-group myresourcegroup --location westus2
86-
8782
```
8883

8984
This command performs the following actions, which may take a few minutes:
9085

9186
- Create the resource group if it doesn't already exist.
92-
- Generates a server name if it is not provided.
87+
- Generates a server name if it isn't provided.
9388
- Create a new virtual network for your new postgreSQL server. **Make a note of virtual network name and subnet name** created for your server since you need to add the web app to the same virtual network.
94-
- Creates admin username , password for your server if not provided. **Make a note of the username and password** to use in the next step.
89+
- Creates admin username, password for your server if not provided. **Make a note of the username and password** to use in the next step.
9590
- Create a database ```postgres``` that can be used for development. You can run [**psql** to connect to the database](quickstart-create-server-portal.md#connect-to-the-postgresql-database-using-psql) to create a different database.
9691

9792
> [!NOTE]
98-
> Make a note of your password that will be generate for you if not provided. If you forget the password you would have to reset the password using ``` az postgres flexible-server update``` command
99-
93+
> Make a note of your password that will be generate for you if not provided. If you forget the password you would have to reset the password using `az postgres flexible-server update` command
10094
10195
## Deploy the code to Azure App Service
10296

10397
In this section, you create app host in App Service app, connect this app to the Postgres database, then deploy your code to that host.
10498

105-
10699
### Create the App Service web app in a virtual network
107100

108101
In the terminal, make sure you're in the repository root (`djangoapp`) that contains the app code.
109102

110103
Create an App Service app (the host process) with the [`az webapp up`](/cli/azure/webapp#az-webapp-up) command:
111104

112105
```azurecli
113-
114106
# Create a web app
115107
116-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
117108
az webapp up --resource-group myresourcegroup --location westus2 --plan DjangoPostgres-tutorial-plan --sku B1 --name <app-name>
118109
119110
# Enable VNET integration for web app.
120111
121-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
122112
# Replace <vnet-name> and <subnet-name> with the virtual network and subnet name that the flexible server is using.
123113
124-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
125-
126114
az webapp vnet-integration add -g myresourcegroup -n mywebapp --vnet <vnet-name> --subnet <subnet-name>
127115
128116
# Configure database information as environment variables
129117
130-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
131118
# Use the postgres server name , database name , username , password for the database created in the previous steps
132119
133-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
134-
135120
az webapp config appsettings set --settings DJANGO_ENV="production" DBHOST="<postgres-server-name>.postgres.database.azure.com" DBNAME="postgres" DBUSER="<username>" DBPASS="<password>"
136121
```
137122
- For the `--location` argument, use the same location as you did for the database in the previous section.
@@ -141,7 +126,7 @@ az webapp config appsettings set --settings DJANGO_ENV="production" DBHOST="<pos
141126
- Enable default logging for the app, if not already enabled.
142127
- Upload the repository using ZIP deployment with build automation enabled.
143128
- **az webapp vnet-integration** command adds the web app in the same virtual network as the postgres server.
144-
- The app code expects to find database information in a number of environment variables. To set environment variables in App Service, you create "app settings" with the [az webapp config appsettings set](/cli/azure/webapp/config/appsettings#az-webapp-config-appsettings-set) command.
129+
- The app code expects to find database information in many environment variables. To set environment variables in App Service, you create "app settings" with the [az webapp config appsettings set](/cli/azure/webapp/config/appsettings#az-webapp-config-appsettings-set) command.
145130

146131
> [!TIP]
147132
> Many Azure CLI commands cache common parameters, such as the name of the resource group and App Service plan, into the file *.azure/config*. As a result, you don't need to specify all the same parameter with later commands. For example, to redeploy the app after making changes, you can just run `az webapp up` again without any parameters.
@@ -152,7 +137,7 @@ Django database migrations ensure that the schema in the PostgreSQL on Azure dat
152137

153138
1. Open an SSH session in the browser by navigating to *https://\<app-name>.scm.azurewebsites.net/webssh/host* and sign in with your Azure account credentials (not the database server credentials).
154139

155-
1. In the SSH session, run the following commands (you can paste commands using **Ctrl**+**Shift**+**V**):
140+
2. In the SSH session, run the following commands (you can paste commands using **Ctrl**+**Shift**+**V**):
156141

157142
```bash
158143
cd site/wwwroot
@@ -167,15 +152,15 @@ Django database migrations ensure that the schema in the PostgreSQL on Azure dat
167152
python manage.py createsuperuser
168153
```
169154

170-
1. The `createsuperuser` command prompts you for superuser credentials. For the purposes of this tutorial, use the default username `root`, press **Enter** for the email address to leave it blank, and enter `postgres1` for the password.
155+
3. The `createsuperuser` command prompts you for superuser credentials. For the purposes of this tutorial, use the default username `root`, press **Enter** for the email address to leave it blank, and enter `postgres1` for the password.
171156

172157
### Create a poll question in the app
173158

174-
1. In a browser, open the URL *http:\//\<app-name>.azurewebsites.net*. The app should display the message "No polls are available" because there are no specific polls yet in the database.
159+
4. In a browser, open the URL *http:\//\<app-name>.azurewebsites.net*. The app should display the message "No polls are available" because there are no specific polls yet in the database.
175160

176-
1. Browse to *http:\//\<app-name>.azurewebsites.net/admin*. Sign in using superuser credentials from the previous section (`root` and `postgres1`). Under **Polls**, select **Add** next to **Questions** and create a poll question with some choices.
161+
5. Browse to *http:\//\<app-name>.azurewebsites.net/admin*. Sign in using superuser credentials from the previous section (`root` and `postgres1`). Under **Polls**, select **Add** next to **Questions** and create a poll question with some choices.
177162

178-
1. Browse again to *http:\//\<app-name>.azurewebsites.net/* to confirm that the questions are now presented to the user. Answer questions however you like to generate some data in the database.
163+
6. Browse again to *http:\//\<app-name>.azurewebsites.net/* to confirm that the questions are now presented to the user. Answer questions however you like to generate some data in the database.
179164

180165
**Congratulations!** You're running a Python Django web app in Azure App Service for Linux, with an active Postgres database.
181166
@@ -193,25 +178,20 @@ In a terminal window, run the following commands. Be sure to follow the prompts
193178
```bash
194179
# Configure the Python virtual environment
195180
196-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
197181
python3 -m venv venv
198182
source venv/bin/activate
199183
200184
# Install packages
201185
202-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
203186
pip install -r requirements.txt
204187
# Run Django migrations
205188
206-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
207189
python manage.py migrate
208190
# Create Django superuser (follow prompts)
209191
210-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
211192
python manage.py createsuperuser
212193
# Run the dev server
213194
214-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
215195
python manage.py runserver
216196
```
217197
Once the web app is fully loaded, the Django development server provides the local app URL in the message, "Starting development server at http://127.0.0.1:8000/. Quit the server with CTRL-BREAK".
@@ -222,30 +202,27 @@ Test the app locally with the following steps:
222202
223203
1. Go to *http:\//localhost:8000* in a browser, which should display the message "No polls are available".
224204
225-
1. Go to *http:\//localhost:8000/admin* and sign in using the admin user you created previously. Under **Polls**, again select **Add** next to **Questions** and create a poll question with some choices.
205+
2. Go to *http:\//localhost:8000/admin* and sign in using the admin user you created previously. Under **Polls**, again select **Add** next to **Questions** and create a poll question with some choices.
226206
227-
1. Go to *http:\//localhost:8000* again and answer the question to test the app.
207+
3. Go to *http:\//localhost:8000* again and answer the question to test the app.
228208
229-
1. Stop the Django server by pressing **Ctrl**+**C**.
209+
4. Stop the Django server by pressing **Ctrl**+**C**.
230210
231211
When running locally, the app is using a local Sqlite3 database and doesn't interfere with your production database. You can also use a local PostgreSQL database, if desired, to better simulate your production environment.
232212

233-
234-
235213
### Update the app
236214

237215
In `polls/models.py`, locate the line that begins with `choice_text` and change the `max_length` parameter to 100:
238216

239217
```python
240218
# Find this lie of code and set max_length to 100 instead of 200
241219
242-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
243220
choice_text = models.CharField(max_length=100)
244221
```
245222

246223
Because you changed the data model, create a new Django migration and migrate the database:
247224

248-
```
225+
```python
249226
python manage.py makemigrations
250227
python manage.py migrate
251228
```
@@ -265,8 +242,6 @@ az webapp up
265242

266243
This command uses the parameters cached in the *.azure/config* file. Because App Service detects that the app already exists, it just redeploys the code.
267244

268-
269-
270245
### Rerun migrations in Azure
271246

272247
Because you made changes to the data model, you need to rerun database migrations in App Service.
@@ -278,11 +253,9 @@ cd site/wwwroot
278253
279254
# Activate default virtual environment in App Service container
280255
281-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
282256
source /antenv/bin/activate
283257
# Run database migrations
284258
285-
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
286259
python manage.py migrate
287260
```
288261

@@ -304,7 +277,6 @@ By default, the portal shows your app's **Overview** page, which provides a gene
304277
305278
:::image type="content" source="./media/tutorial-django-app-service-postgres/manage-django-app-in-app-services-in-the-azure-portal.png" alt-text="Manage your Python Django app in the Overview page in the Azure portal":::
306279
307-
308280
## Clean up resources
309281
310282
If you'd like to keep the app or continue to the next tutorial, skip ahead to [Next steps](#next-steps). Otherwise, to avoid incurring ongoing charges you can delete the resource group create for this tutorial:

0 commit comments

Comments
 (0)