Advertisement
Guest User

Untitled

a guest
Mar 15th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. https://cloud.google.com/python/django/flexible-environment
  2.  
  3. host = '127.0.0.1' also changed to 35.196.etc
  4. user = 'me'
  5. password = 'pwd'
  6.  
  7. conn1 = pymysql.connect(host=host,
  8. user=user,
  9. password=password,
  10. db='retail_data')
  11. cur1 = conn1.cursor()
  12.  
  13. "listening on 127.0.0.1:3306 for scoviileapp:us-east1:retail18
  14. ready for new connections"
  15.  
  16. gcloud app deploy
  17.  
  18. https://scovilleapp.appspot.com/search/?fname=james&mname=g&lname=stahl&street_num=1045&street_name=beck&street_type=rd&state=OH&zip=48233
  19.  
  20. app.yaml
  21. # [START django_app]
  22. # [START runtime]
  23. runtime: python
  24. threadsafe: yes
  25. env: flex
  26. entrypoint: gunicorn -b :$PORT scoville_matching_app.wsgi
  27.  
  28. beta_settings:
  29. cloud_sql_instances: 'scovilleapp:us-east1:retail18'
  30.  
  31. runtime_config:
  32. python_version: 3.5
  33. # [END runtime]
  34.  
  35. handlers:
  36. - url: /static
  37. static_dir: static/
  38. - url: /.*
  39. script: main.application
  40.  
  41. # Only pure Python libraries can be vendored
  42. # Python libraries that use C extensions can
  43. # only be included if they are part of the App Engine SDK
  44.  
  45. #[START env]
  46. env_variables:
  47. # Replace user, password, database, and instance connection name with the values obtained
  48. # when configuring your Cloud SQL instance.
  49. SQLALCHEMY_DATABASE_URI: >-
  50. mysql+pymysql://root:secret@/retail_service_data?unix_socket=/cloudsql/scovilleapp:us-east1:retail18
  51.  
  52. My settings file:
  53.  
  54. import os
  55.  
  56. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  57. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  58.  
  59.  
  60. ALLOWED_HOSTS = ['*']
  61.  
  62.  
  63. # Application definition
  64.  
  65. INSTALLED_APPS = [
  66. 'django.contrib.admin',
  67. 'django.contrib.auth',
  68. 'django.contrib.contenttypes',
  69. 'django.contrib.sessions',
  70. 'django.contrib.messages',
  71. 'django.contrib.staticfiles',
  72. 'scovilleapp', #name of the app we added
  73. ]
  74.  
  75.  
  76. ROOT_URLCONF = 'scoville_matching_app.urls'
  77.  
  78. TEMPLATES = [
  79. {
  80. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  81. 'DIRS': [],
  82. 'APP_DIRS': True,
  83. 'OPTIONS': {
  84. 'context_processors': [
  85. 'django.template.context_processors.debug',
  86. 'django.template.context_processors.request',
  87. 'django.contrib.auth.context_processors.auth',
  88. 'django.contrib.messages.context_processors.messages',
  89. ],
  90. },
  91. },
  92. ]
  93.  
  94. WSGI_APPLICATION = 'scoville_matching_app.wsgi.application'
  95.  
  96.  
  97. # Database
  98. # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
  99.  
  100. # Check to see if MySQLdb is available; if not, have pymysql masquerade as
  101. # MySQLdb. This is a convenience feature for developers who cannot install
  102. # MySQLdb locally; when running in production on Google App Engine Standard
  103. # Environment, MySQLdb will be used.
  104. try:
  105. import MySQLdb # noqa: F401
  106. except ImportError:
  107. import pymysql
  108. pymysql.install_as_MySQLdb()
  109.  
  110.  
  111. # [START dbconfig]
  112. DATABASES = {
  113. 'default': {
  114. # If you are using Cloud SQL for MySQL rather than PostgreSQL, set
  115. # 'ENGINE': 'django.db.backends.mysql' instead of the following.
  116. 'ENGINE': 'django.db.backends.mysql',
  117. 'NAME': 'retail_service_data',
  118. 'USER': 'me',
  119. 'PASSWORD': 'pwd',
  120. # For MySQL, set 'PORT': '3306' instead of the following. Any Cloud
  121. # SQL Proxy instances running locally must also be set to tcp:3306.
  122. 'PORT': '3306',
  123. }
  124. }
  125. # [END db_setup]
  126. # In the flexible environment, you connect to CloudSQL using a unix socket.
  127. # Locally, you can use the CloudSQL proxy to proxy a localhost connection
  128. # to the instance
  129. DATABASES['default']['HOST'] = '/cloudsql/scovilleapp:us-east1:retail18'
  130. if os.getenv('GAE_INSTANCE'):
  131. pass
  132. else:
  133. DATABASES['default']['HOST'] = '127.0.0.1'
  134. # [END dbconfig]
  135.  
  136. # Password validation
  137. # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
  138.  
  139. AUTH_PASSWORD_VALIDATORS = [
  140. {
  141. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  142. },
  143. {
  144. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  145. },
  146. {
  147. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  148. },
  149. {
  150. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  151. },
  152. ]
  153.  
  154.  
  155. LANGUAGE_CODE = 'en-us'
  156.  
  157. TIME_ZONE = 'UTC'
  158.  
  159. USE_I18N = True
  160.  
  161. USE_L10N = True
  162.  
  163. USE_TZ = True
  164.  
  165.  
  166. # [START staticurl]
  167. # Fill in your cloud bucket and switch which one of the following 2 lines
  168. # is commented to serve static content from GCS
  169. # STATIC_URL = 'https://storage.googleapis.com/<your-gcs-bucket>/static/'
  170. STATIC_URL = 'https://storage.googleapis.com/scovilleapp/static/'
  171. STATIC_ROOT = os.path.join(BASE_DIR, 'static')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement