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 54f1947

Browse filesBrowse files
ryanmatsJon Wayne Parrott
authored andcommitted
Changes for new Django update + README redirects to tutorial (GoogleCloudPlatform#704)
1 parent 5ab0c25 commit 54f1947
Copy full SHA for 54f1947

File tree

Expand file treeCollapse file tree

2 files changed

+8
-110
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-110
lines changed

‎appengine/flexible/django_cloudsql/README.md

Copy file name to clipboardExpand all lines: appengine/flexible/django_cloudsql/README.md
+2-108Lines changed: 2 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -6,115 +6,9 @@ app on Google App Engine Flexible Environment. It uses the
66
example app to deploy.
77

88

9-
## Setup the database
9+
# Tutorial
10+
See our [Running Django in the App Engine Flexible Environment](https://cloud.google.com/python/django/flexible-environment) tutorial for instructions for setting up and deploying this sample application.
1011

11-
This tutorial assumes you are setting up Django using a SQL database, which is the easiest way to
12-
run Django.
13-
14-
* Create a [Second Generation CloudSQL instance](https://cloud.google.com/sql/docs/create-instance)
15-
16-
* Ensure the [Cloud SQL Administration API](https://console.cloud.google.com/flows/enableapi?apiid=sqladmin) is enabled.
17-
18-
* Install the [CloudSQL proxy](https://cloud.google.com/sql/docs/sql-proxy)
19-
20-
* Start the CloudSQL proxy using the connection string. The connection string can be obtained in the
21-
instance details in the console. It's in the form of <project>:<region>:<instance-name>.
22-
23-
./cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
24-
25-
* Create a root password
26-
27-
`gcloud sql instances set-root-password [YOUR_INSTANCE_NAME] --password [YOUR_INSTANCE_ROOT_PASSWORD]`
28-
29-
* Use the root user and root password to create the `polls` database:
30-
31-
`mysql -h 127.0.0.1 -u root -p -e "CREATE DATABASE polls;"`
32-
33-
* Edit `app.yaml` to change the `cloud_sql_instances` to reflect the connection name of the
34-
instance. This is in the form project:zone:instance
35-
36-
* Optionally, use the root account to create a new MySQL user.
37-
38-
`mysql -h 127.0.0.1 -u root -p -e "CREATE USER 'user'@'%' IDENTIFIED BY 'password';" ``
39-
`mysql -h 127.0.0.1 -u root -p -e "GRANT ALL PRIVILEGES ON * . * TO 'user'@'%';" ``
40-
41-
Once you have a SQL host, configuring mysite/settings.py to point to your database. Change
42-
`your-cloudsql-connection-string` and `your-root-password`. If you created a new user and
43-
password, update those settings as well.
44-
45-
## Running locally
46-
47-
First make sure you have Django installed. It's recommended you do so in a
48-
[virtualenv](https://virtualenv.pypa.io/en/latest/). The requirements.txt
49-
contains just the Django dependency.
50-
51-
pip install -r requirements.txt
52-
53-
Once the database is setup, run the migrations.
54-
55-
python manage.py makemigrations
56-
python manage.py makemigrations polls
57-
python manage.py migrate
58-
59-
If you'd like to use the admin console, create a superuser.
60-
61-
python manage.py createsuperuser
62-
63-
The app can be run locally the same way as any other Django app.
64-
65-
python manage.py runserver
66-
67-
Now you can view the admin panel of your local site at http://localhost:8000/admin
68-
69-
## Deploying
70-
71-
The app can be deployed by running
72-
73-
gcloud app deploy
74-
75-
You can view your site with:
76-
77-
gcloud app browse
78-
79-
Now you can view the admin panel of your deployed site at https://<your-app-id>.appspot.com/admin
80-
81-
82-
### Serving Static Files Using Cloud Storage
83-
84-
Since the Django development server is not built for production, our container uses the Gunicorn
85-
server. In `mysite/urls.py`, while in DEBUG mode, Django is configured to serve static files.
86-
However, in production, it's recommended to use Google Cloud Storage or an alternative CDN for
87-
serving static files.
88-
89-
First, make a bucket and make it publically readable, replacing <your-gcs-bucket> with a bucket name
90-
, such as your project id:
91-
92-
gsutil mb gs://<your-gcs-bucket>
93-
gsutil defacl set public-read gs://<your-gcs-bucket>
94-
95-
Next, gather all the static content locally into one folder using the Django `collectstatic` command
96-
97-
python manage.py collectstatic
98-
99-
Then upload it to CloudStorage using the `gsutil rsync` command
100-
101-
gsutil rsync -R static/ gs://<your-gcs-bucket>/static
102-
103-
Now your static content can be served from the following URL:
104-
105-
http://storage.googleapis.com/<your-gcs-bucket/static/
106-
107-
Make sure to replace <your-cloud-bucket> within `mysite/settings.py` to set STATIC_URL to the
108-
correct value to serve static content from, and uncomment the STATIC_URL to point to the new URL.
109-
110-
### Production
111-
112-
Once you are ready to serve your content in production, there are several
113-
changes required for the configuration. Most notable changes are:
114-
115-
* Use Google Cloud Storage or a CDN to serve static files
116-
* Add ".appspot.com" to your `ALLOWED_HOSTS`
117-
* Change the `DEBUG` variable to `False` in your settings.py file.
11812

11913
## Contributing changes
12014

‎appengine/flexible/django_cloudsql/mysite/settings.py

Copy file name to clipboardExpand all lines: appengine/flexible/django_cloudsql/mysite/settings.py
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
# SECURITY WARNING: don't run with debug turned on in production!
2727
DEBUG = True
2828

29-
ALLOWED_HOSTS = []
29+
# SECURITY WARNING: App Engine's security features ensure that it is safe to
30+
# have ALLOWED_HOSTS = ['*'] when the app is deployed. If you deploy a Django
31+
# app not on App Engine, make sure to set an appropriate host here.
32+
# See https://docs.djangoproject.com/en/1.10/ref/settings/
33+
ALLOWED_HOSTS = ['*']
3034

3135
# Application definition
3236

@@ -112,7 +116,7 @@
112116
# [START staticurl]
113117
# Fill in your cloud bucket and switch which one of the following 2 lines
114118
# is commented to serve static content from GCS
115-
# STATIC_URL = 'https://storage.googleapis.com/<your-cloud-bucket>/static/'
119+
# STATIC_URL = 'https://storage.googleapis.com/<your-gcs-bucket>/static/'
116120
STATIC_URL = '/static/'
117121
# [END staticurl]
118122

0 commit comments

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