Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://cloud.google.com/python/django/flexible-environment
- host = '127.0.0.1' also changed to 35.196.etc
- user = 'me'
- password = 'pwd'
- conn1 = pymysql.connect(host=host,
- user=user,
- password=password,
- db='retail_data')
- cur1 = conn1.cursor()
- "listening on 127.0.0.1:3306 for scoviileapp:us-east1:retail18
- ready for new connections"
- gcloud app deploy
- https://scovilleapp.appspot.com/search/?fname=james&mname=g&lname=stahl&street_num=1045&street_name=beck&street_type=rd&state=OH&zip=48233
- app.yaml
- # [START django_app]
- # [START runtime]
- runtime: python
- threadsafe: yes
- env: flex
- entrypoint: gunicorn -b :$PORT scoville_matching_app.wsgi
- beta_settings:
- cloud_sql_instances: 'scovilleapp:us-east1:retail18'
- runtime_config:
- python_version: 3.5
- # [END runtime]
- handlers:
- - url: /static
- static_dir: static/
- - url: /.*
- script: main.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
- #[START env]
- env_variables:
- # Replace user, password, database, and instance connection name with the values obtained
- # when configuring your Cloud SQL instance.
- SQLALCHEMY_DATABASE_URI: >-
- mysql+pymysql://root:secret@/retail_service_data?unix_socket=/cloudsql/scovilleapp:us-east1:retail18
- My settings file:
- import os
- # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- ALLOWED_HOSTS = ['*']
- # Application definition
- INSTALLED_APPS = [
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'scovilleapp', #name of the app we added
- ]
- ROOT_URLCONF = 'scoville_matching_app.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 = 'scoville_matching_app.wsgi.application'
- # Database
- # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
- # Check to see if MySQLdb is available; if not, have pymysql masquerade as
- # MySQLdb. This is a convenience feature for developers who cannot install
- # MySQLdb locally; when running in production on Google App Engine Standard
- # Environment, MySQLdb will be used.
- try:
- import MySQLdb # noqa: F401
- except ImportError:
- import pymysql
- pymysql.install_as_MySQLdb()
- # [START dbconfig]
- DATABASES = {
- 'default': {
- # If you are using Cloud SQL for MySQL rather than PostgreSQL, set
- # 'ENGINE': 'django.db.backends.mysql' instead of the following.
- 'ENGINE': 'django.db.backends.mysql',
- 'NAME': 'retail_service_data',
- 'USER': 'me',
- 'PASSWORD': 'pwd',
- # For MySQL, set 'PORT': '3306' instead of the following. Any Cloud
- # SQL Proxy instances running locally must also be set to tcp:3306.
- 'PORT': '3306',
- }
- }
- # [END db_setup]
- # In the flexible environment, you connect to CloudSQL using a unix socket.
- # Locally, you can use the CloudSQL proxy to proxy a localhost connection
- # to the instance
- DATABASES['default']['HOST'] = '/cloudsql/scovilleapp:us-east1:retail18'
- if os.getenv('GAE_INSTANCE'):
- pass
- else:
- DATABASES['default']['HOST'] = '127.0.0.1'
- # [END dbconfig]
- # Password validation
- # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
- AUTH_PASSWORD_VALIDATORS = [
- {
- 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
- },
- {
- 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
- },
- {
- 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
- },
- {
- 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
- },
- ]
- LANGUAGE_CODE = 'en-us'
- TIME_ZONE = 'UTC'
- USE_I18N = True
- USE_L10N = True
- USE_TZ = True
- # [START staticurl]
- # Fill in your cloud bucket and switch which one of the following 2 lines
- # is commented to serve static content from GCS
- # STATIC_URL = 'https://storage.googleapis.com/<your-gcs-bucket>/static/'
- STATIC_URL = 'https://storage.googleapis.com/scovilleapp/static/'
- STATIC_ROOT = os.path.join(BASE_DIR, 'static')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement