Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 59ce5e7

Browse filesBrowse files
fix: fix from-scratch tutorial (#573)
1 parent 65d2e9d commit 59ce5e7
Copy full SHA for 59ce5e7

File tree

1 file changed

+43
-7
lines changed
Filter options

1 file changed

+43
-7
lines changed

‎examples/from-scratch/README.md

Copy file name to clipboardExpand all lines: examples/from-scratch/README.md
+43-7Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
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/)
44

5+
*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.)
6+
57
### Walkthrough the introduction to Django
68

79
### Install django-spanner
8-
We'll need to install `django-spanner`, by cloning this repository and then running `pip3 install`
10+
To install from PyPI:
11+
```shell
12+
pip3 install django-google-spanner
13+
```
14+
To install from source:
915
```shell
10-
git clone https://github.com/googleapis/django-spanner
16+
git clone https://github.com/googleapis/python-spanner-django
17+
cd python-spanner-django/
1118
pip3 install .
1219
```
1320

@@ -26,7 +33,7 @@ After we have a Cloud Spanner database created, we'll need a few variables:
2633
* Instance name
2734
* Database name aka DisplayName
2835

29-
Once in, please edit the file `hc/local_settings.py`, and:
36+
Once in, edit the DATABASES section of your mysite/settings.py file to the following:
3037

3138
a) add `django_spanner` as the very first entry to your `INSTALLED_APPS`
3239
```python
@@ -51,8 +58,8 @@ DATABASES = {
5158
and for example here is a filled in database where:
5259

5360
* `PROJECT_ID`: spanner-appdev
54-
* INSTANCE: instance
55-
* NAME: `healthchecks_db`
61+
* `INSTANCE`: instance
62+
* `NAME`: db1
5663

5764
which when filled out, will look like this
5865

@@ -62,11 +69,17 @@ DATABASES = {
6269
'ENGINE': 'django_spanner',
6370
'PROJECT': 'spanner-appdev',
6471
'INSTANCE': 'instance',
65-
'NAME': 'healthchecks_db',
72+
'NAME': 'db1',
6673
}
6774
}
6875
```
6976

77+
### Set Google Application Default Credentials to the environment
78+
You'll need to download a service account JSON key file and point to it using an environment variable:
79+
```shell
80+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/keyfile.json
81+
```
82+
7083
### Apply the migrations
7184
Please run:
7285
```shell
@@ -102,13 +115,36 @@ Running migrations:
102115
```
103116
</details>
104117

118+
After this you should can see the tables and indices created in your Cloud Spanner console
119+
105120
### Now run your server
106121
After those migrations are completed, that will be all. Please continue on with the guides.
107122

123+
### Create an Django admin user
124+
First you’ll need to create a user who can login to the admin site. Run the following command:
125+
126+
```shell
127+
$ python3 manage.py createsuperuser
128+
```
129+
which will then produce a prompt which will allow you to create your super user
130+
```shell
131+
Username: admin
132+
Email address: admin@example.com
133+
Password: **********
134+
Password (again): **********
135+
Superuser created successfully.
136+
```
137+
138+
### Login as admin
139+
Let’s run the server
140+
```shell script
141+
python3 manage.py runserver
142+
```
143+
Then visit http://127.0.0.1:8000/admin/
144+
108145
### Comprehensive hands-on guide
109146
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/)
110147

111-
112148
### References
113149

114150
Resource|URL

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.