-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix from-scratch tutorial (#573)
- Loading branch information
1 parent
65d2e9d
commit 59ce5e7
Showing
1 changed file
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,19 @@ | |
|
||
This example shows how to use django-spanner for Cloud Spanner as a backend database for [Django's tutorials](https://docs.djangoproject.com/en/2.2/intro/tutorial01/) | ||
|
||
*NOTE:* Use the version of python-spanner-django that corresponds to your version of Django. For example, python-spanner-django 2.2.x works with Django 2.2.y. (This is the only supported version at this time.) | ||
|
||
### Walkthrough the introduction to Django | ||
|
||
### Install django-spanner | ||
We'll need to install `django-spanner`, by cloning this repository and then running `pip3 install` | ||
To install from PyPI: | ||
```shell | ||
pip3 install django-google-spanner | ||
``` | ||
To install from source: | ||
```shell | ||
git clone https://github.com/googleapis/django-spanner | ||
git clone https://github.com/googleapis/python-spanner-django | ||
cd python-spanner-django/ | ||
pip3 install . | ||
``` | ||
|
||
|
@@ -26,7 +33,7 @@ After we have a Cloud Spanner database created, we'll need a few variables: | |
* Instance name | ||
* Database name aka DisplayName | ||
|
||
Once in, please edit the file `hc/local_settings.py`, and: | ||
Once in, edit the DATABASES section of your mysite/settings.py file to the following: | ||
|
||
a) add `django_spanner` as the very first entry to your `INSTALLED_APPS` | ||
```python | ||
|
@@ -51,8 +58,8 @@ DATABASES = { | |
and for example here is a filled in database where: | ||
|
||
* `PROJECT_ID`: spanner-appdev | ||
* INSTANCE: instance | ||
* NAME: `healthchecks_db` | ||
* `INSTANCE`: instance | ||
* `NAME`: db1 | ||
|
||
which when filled out, will look like this | ||
|
||
|
@@ -62,11 +69,17 @@ DATABASES = { | |
'ENGINE': 'django_spanner', | ||
'PROJECT': 'spanner-appdev', | ||
'INSTANCE': 'instance', | ||
'NAME': 'healthchecks_db', | ||
'NAME': 'db1', | ||
} | ||
} | ||
``` | ||
|
||
### Set Google Application Default Credentials to the environment | ||
You'll need to download a service account JSON key file and point to it using an environment variable: | ||
```shell | ||
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/keyfile.json | ||
``` | ||
|
||
### Apply the migrations | ||
Please run: | ||
```shell | ||
|
@@ -102,13 +115,36 @@ Running migrations: | |
``` | ||
</details> | ||
|
||
After this you should can see the tables and indices created in your Cloud Spanner console | ||
|
||
### Now run your server | ||
After those migrations are completed, that will be all. Please continue on with the guides. | ||
|
||
### Create an Django admin user | ||
First you’ll need to create a user who can login to the admin site. Run the following command: | ||
|
||
```shell | ||
$ python3 manage.py createsuperuser | ||
``` | ||
which will then produce a prompt which will allow you to create your super user | ||
```shell | ||
Username: admin | ||
Email address: [email protected] | ||
Password: ********** | ||
Password (again): ********** | ||
Superuser created successfully. | ||
``` | ||
|
||
### Login as admin | ||
Let’s run the server | ||
```shell script | ||
python3 manage.py runserver | ||
``` | ||
Then visit http://127.0.0.1:8000/admin/ | ||
|
||
### Comprehensive hands-on guide | ||
For a more comprehensive, step by step hands-on guide, please visit [using django-spanner from scratch](https://orijtech-161805.firebaseapp.com/quickstart/new_app/) | ||
|
||
|
||
### References | ||
|
||
Resource|URL | ||
|