-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Updated Django GAE Standard Sample to CloudSQL v2 and Django 1.10 #714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
429ce18
2348ab7
569094f
372a69a
9ffcdb1
53050d2
505c42a
0d7e33c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # How to become a contributor and submit your own code | ||
|
|
||
| ## Contributor License Agreements | ||
|
|
||
| We'd love to accept your sample apps and patches! Before we can take them, we | ||
| have to jump a couple of legal hurdles. | ||
|
|
||
| Please fill out either the individual or corporate Contributor License Agreement | ||
| (CLA). | ||
|
|
||
| * If you are an individual writing original source code and you're sure you | ||
| own the intellectual property, then you'll need to sign an [individual CLA] | ||
| (https://developers.google.com/open-source/cla/individual). | ||
| * If you work for a company that wants to allow you to contribute your work, | ||
| then you'll need to sign a [corporate CLA] | ||
| (https://developers.google.com/open-source/cla/corporate). | ||
|
|
||
| Follow either of the two links above to access the appropriate CLA and | ||
| instructions for how to sign and return it. Once we receive it, we'll be able to | ||
| accept your pull requests. | ||
|
|
||
| ## Contributing A Patch | ||
|
|
||
| 1. Submit an issue describing your proposed change to the repo in question. | ||
| 1. The repo owner will respond to your issue promptly. | ||
| 1. If your proposed change is accepted, and you haven't already done so, sign a | ||
| Contributor License Agreement (see details above). | ||
| 1. Fork the desired repo, develop and test your code changes. | ||
| 1. Ensure that your code adheres to the existing style in the sample to which | ||
| you are contributing. Refer to the | ||
| [Google Cloud Platform Samples Style Guide] | ||
| (https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the | ||
| recommended coding standards for this organization. | ||
| 1. Ensure that your code has an appropriate set of unit tests which all pass. | ||
| 1. Submit a pull request. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| Copyright (c) Waldemar Kornewald, Thomas Wanschik, and all contributors. | ||
|
||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without modification, | ||
| are permitted provided that the following conditions are met: | ||
|
|
||
| 1. Redistributions of source code must retain the above copyright notice, | ||
| this list of conditions and the following disclaimer. | ||
|
|
||
| 2. Redistributions in binary form must reproduce the above copyright | ||
| notice, this list of conditions and the following disclaimer in the | ||
| documentation and/or other materials provided with the distribution. | ||
|
|
||
| 3. Neither the name of All Buttons Pressed nor | ||
| the names of its contributors may be used to endorse or promote products | ||
| derived from this software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
| ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Getting started with Django on Google Cloud Platform on App Engine Standard | ||
|
|
||
| This repository is an example of how to run a [Django](https://www.djangoproject.com/) | ||
| app on Google App Engine Flexible Environment. It uses the | ||
| [Writing your first Django app](https://docs.djangoproject.com/en/1.9/intro/tutorial01/) as the | ||
| example app to deploy. | ||
|
|
||
|
|
||
| # Tutorial | ||
| See our [Running Django in the App Engine Standard Environment](https://cloud.google.com/python/django/appengine) tutorial for instructions for setting up and deploying this sample application. | ||
|
|
||
|
|
||
| ## Contributing changes | ||
|
||
|
|
||
| * See [CONTRIBUTING.md](CONTRIBUTING.md) | ||
|
|
||
|
|
||
| ## Licensing | ||
|
|
||
| * See [LICENSE](LICENSE) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Copyright 2015 Google Inc. | ||
|
||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # This file specifies your Python application's runtime configuration. | ||
| # See https://cloud.google.com/appengine/docs/managed-vms/config for details. | ||
|
|
||
| # [START django_app] | ||
| runtime: python27 | ||
| api_version: 1 | ||
| threadsafe: yes | ||
|
|
||
| handlers: | ||
| - url: /static | ||
| static_dir: static/ | ||
| - url: .* | ||
| script: mysite.wsgi.application | ||
|
|
||
| # Only pure Python libraries can be vendored | ||
| # Python libraries that use C extensions can | ||
| # only be included if they are part of the App Engine SDK | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a link here to the documentation on third-party libraries.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| libraries: | ||
| - name: MySQLdb | ||
| version: 1.2.5 | ||
| # [END django_app] | ||
|
|
||
| skip_files: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment here explaining why this is necessary and what you changed from the default.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| - ^(.*/)?#.*#$ | ||
| - ^(.*/)?.*~$ | ||
| - ^(.*/)?.*\.py[co]$ | ||
| - ^(.*/)?.*/RCS/.*$ | ||
| - ^(.*/)?\..*$ | ||
| - ^env/.*$ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Copyright 2015 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # [START vendor] | ||
| from google.appengine.ext import vendor | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank newline between imports and statements, please.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| vendor.add('lib') | ||
| # [END vendor] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #!/usr/bin/env python | ||
| # Copyright 2015 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| if __name__ == "__main__": | ||
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") | ||
|
|
||
| from django.core.management import execute_from_command_line | ||
|
|
||
| execute_from_command_line(sys.argv) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| # Copyright 2015 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| Django settings for mysite project. | ||
|
|
||
| Generated by 'django-admin startproject' using Django 1.8.5. | ||
|
|
||
| For more information on this file, see | ||
| https://docs.djangoproject.com/en/1.8/topics/settings/ | ||
|
|
||
| For the full list of settings and their values, see | ||
| https://docs.djangoproject.com/en/1.8/ref/settings/ | ||
| """ | ||
|
|
||
| # Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
| import os | ||
|
|
||
| BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
|
||
|
|
||
| # Quick-start development settings - unsuitable for production | ||
| # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ | ||
|
|
||
| # SECURITY WARNING: keep the secret key used in production secret! | ||
| SECRET_KEY = '-c&qt=71oi^e5s8(ene*$b89^#%*0xeve$x_trs91veok9#0h0' | ||
|
|
||
| # SECURITY WARNING: don't run with debug turned on in production! | ||
| DEBUG = True | ||
|
|
||
| # SECURITY WARNING: App Engine's security features ensure that it is safe to | ||
| # have ALLOWED_HOSTS = ['*'] when the app is deployed. If you deploy a Django | ||
| # app not on App Engine, make sure to set an appropriate host here. | ||
| # See https://docs.djangoproject.com/en/1.10/ref/settings/ | ||
| ALLOWED_HOSTS = ['*'] | ||
|
|
||
| # Application definition | ||
|
|
||
| INSTALLED_APPS = ( | ||
| 'django.contrib.admin', | ||
| 'django.contrib.auth', | ||
| 'django.contrib.contenttypes', | ||
| 'django.contrib.sessions', | ||
| 'django.contrib.messages', | ||
| 'django.contrib.staticfiles', | ||
| 'polls', | ||
| ) | ||
|
|
||
| MIDDLEWARE_CLASSES = ( | ||
| 'django.contrib.sessions.middleware.SessionMiddleware', | ||
| 'django.middleware.common.CommonMiddleware', | ||
| 'django.middleware.csrf.CsrfViewMiddleware', | ||
| 'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
| 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', | ||
| 'django.contrib.messages.middleware.MessageMiddleware', | ||
| 'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
| 'django.middleware.security.SecurityMiddleware', | ||
| ) | ||
|
|
||
| ROOT_URLCONF = 'mysite.urls' | ||
|
|
||
| TEMPLATES = [ | ||
| { | ||
| 'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
| 'DIRS': [], | ||
| 'APP_DIRS': True, | ||
| 'OPTIONS': { | ||
| 'context_processors': [ | ||
| 'django.template.context_processors.debug', | ||
| 'django.template.context_processors.request', | ||
| 'django.contrib.auth.context_processors.auth', | ||
| 'django.contrib.messages.context_processors.messages', | ||
| ], | ||
| }, | ||
| }, | ||
| ] | ||
|
|
||
| WSGI_APPLICATION = 'mysite.wsgi.application' | ||
|
|
||
|
|
||
| # Database | ||
| # https://docs.djangoproject.com/en/1.8/ref/settings/#databases | ||
|
|
||
| # [START db_setup] | ||
| import os | ||
|
||
| if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'): | ||
| # Running on production App Engine, so use a Google Cloud SQL database. | ||
|
||
| DATABASES = { | ||
| 'default': { | ||
| 'ENGINE': 'django.db.backends.mysql', | ||
| 'HOST': '/cloudsql/<your-cloudsql-connection-string>', | ||
| 'NAME': 'polls', | ||
| 'USER': '<your-database-user>', | ||
| 'PASSWORD': '<your-database-password>', | ||
| } | ||
| } | ||
| else: | ||
| DATABASES = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment here like this:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| 'default': { | ||
| 'ENGINE': 'django.db.backends.mysql', | ||
| 'HOST': '127.0.0.1', | ||
| 'PORT': '3306', | ||
| 'NAME': 'polls', | ||
| 'USER': '<your-database-user>', | ||
| 'PASSWORD': '<your-database-password', | ||
| } | ||
| } | ||
| # [END db_setup] | ||
|
|
||
| # Internationalization | ||
| # https://docs.djangoproject.com/en/1.8/topics/i18n/ | ||
|
|
||
| LANGUAGE_CODE = 'en-us' | ||
|
|
||
| TIME_ZONE = 'UTC' | ||
|
|
||
| USE_I18N = True | ||
|
|
||
| USE_L10N = True | ||
|
|
||
| USE_TZ = True | ||
|
|
||
|
|
||
| # Static files (CSS, JavaScript, Images) | ||
| # https://docs.djangoproject.com/en/1.8/howto/static-files/ | ||
|
|
||
| STATIC_ROOT='static' | ||
| STATIC_URL = '/static/' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Copyright 2015 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from django.conf.urls import include, url | ||
| from django.contrib import admin | ||
|
|
||
| from polls.views import index | ||
|
|
||
| urlpatterns = [ | ||
| url(r'^$', index), | ||
| url(r'^admin/', include(admin.site.urls)), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Copyright 2015 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| WSGI config for mysite project. | ||
|
|
||
| It exposes the WSGI callable as a module-level variable named ``application``. | ||
|
|
||
| For more information on this file, see | ||
| https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| from django.core.wsgi import get_wsgi_application | ||
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") | ||
|
|
||
| application = get_wsgi_application() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright 2015 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from django.contrib import admin | ||
|
|
||
| from .models import Question | ||
|
|
||
| admin.site.register(Question) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done