Skip to content

Commit c7375e5

Browse files
authored
Update Django on GKE (GoogleCloudPlatform#6448)
## Description General updates to the Django on GKE tutorial, including bumping django version, removing `polls` hardcoded value, and adding new Django 3.2 specific setting. ## Checklist - [x] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md) - [x] README is updated to include [all relevant information](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#readme-file) - [x] **Tests** pass: `nox -s py-3.6` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [x] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [x] Please **merge** this PR for me once it is approved. - [x] I updated the [CODEOWNERS file](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/.github/CODEOWNERS) with the codeowners for this sample, as I should be a maintainer going forward.
1 parent 4852379 commit c7375e5

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
/jobs/**/*.py @GoogleCloudPlatform/python-samples-owners
4747
/kms/**/*.py @GoogleCloudPlatform/python-samples-owners
4848
/kubernetes_engine/**/*.py @GoogleCloudPlatform/python-samples-owners
49+
/kubernetes_engine/django_tutorial/**/*.py @glasnt @GoogleCloudPlatform/python-samples-owners
4950
/language/**/*.py @telpirion @sirtorry @GoogleCloudPlatform/python-samples-owners
5051
/media/**/*.py @irataxy @GoogleCloudPlatform/python-samples-owners
5152
/memorystore/**/*.py @GoogleCloudPlatform/python-samples-owners

kubernetes_engine/django_tutorial/mysite/settings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
# If you are using Cloud SQL for MySQL rather than PostgreSQL, set
8484
# 'ENGINE': 'django.db.backends.mysql' instead of the following.
8585
'ENGINE': 'django.db.backends.postgresql',
86-
'NAME': 'polls',
86+
'NAME': os.getenv('DATABASE_NAME'),
8787
'USER': os.getenv('DATABASE_USER'),
8888
'PASSWORD': os.getenv('DATABASE_PASSWORD'),
8989
'HOST': '127.0.0.1',
@@ -110,6 +110,12 @@
110110

111111
# [START gke_django_staticconfig]
112112
STATIC_URL = '/static/'
113+
# STATIC_URL = 'https://storage.googleapis.com/[YOUR_GCS_BUCKET]/static/'
113114
# [END gke_django_staticconfig]
114115

115116
STATIC_ROOT = 'static/'
117+
118+
# Default primary key field type
119+
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
120+
121+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

kubernetes_engine/django_tutorial/polls.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ spec:
4949
imagePullPolicy: Always
5050
env:
5151
# [START cloudsql_secrets]
52+
- name: DATABASE_NAME
53+
valueFrom:
54+
secretKeyRef:
55+
name: cloudsql
56+
key: database
5257
- name: DATABASE_USER
5358
valueFrom:
5459
secretKeyRef:

kubernetes_engine/django_tutorial/requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
Django==3.0.2; python_version > '3.5'
2-
Django==2.2.9; python_version == '3.5'
3-
Django==1.11.28;python_version < '3.0'
1+
Django==3.2.5
42
# Uncomment the mysqlclient requirement if you are using MySQL rather than
53
# PostgreSQL. You must also have a MySQL client installed in that case.
64
#mysqlclient==1.4.1

0 commit comments

Comments
 (0)