[英]Django on Google App Engine with Cloud SQL in dev environment
I am trying to create an application with Django on GAE and CloudSQL as the db. 我正在尝试使用Django在GAE和CloudSQL上创建一个应用程序作为数据库。
I used this google developers link and this link for setting up the dev-environment. 我使用这个谷歌开发人员链接和这个链接来设置开发环境。 I am not able to connect to local mysql db.
我无法连接到本地mysql数据库。
Here is the DATABASE setting which I am trying to use. 这是我正在尝试使用的DATABASE设置。
if (os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine') or
os.getenv('SETTINGS_MODE') == 'prod'):
DATABASES = {
'default': {
'ENGINE': 'google.appengine.ext.django.backends.rdbms',
'INSTANCE': 'instance:appid',
'NAME': 'database_name',
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'USER': 'root',
'PASSWORD': '',
'HOST': 'localhost',
'NAME': 'database_name',
}
}
My app is working perfectly on production GAE, but when I try to start the app on dev env, I am getting this error 我的应用程序完全适用于生产GAE,但当我尝试在dev env上启动应用程序时,我收到此错误
File "/home/sandeep/Downloads/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 635, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.4-py2.7-linux-x86_64.egg'
Complete stack-trace at http://pastebin.com/ZXHv0FPQ 在http://pastebin.com/ZXHv0FPQ上完成堆栈跟踪
I had installed the "python-mysql" by downloading the source and running "python setup.py install" 我通过下载源并运行“python setup.py install”安装了“python-mysql”
Edit 1 编辑1
I have also tried adding the MySQLdb to the library. 我也尝试将MySQLdb添加到库中。
- name: MySQLdb
version: "latest"
Got this error 得到了这个错误
the library "MySQLdb" is not supported
in "/home/sandeep/development/UploadImage/src/app.yaml", line 14, column 1
EDIT 2 编辑2
Django syncdb is working fine with this settings and django is able to create the tables for me.But,when I try to run via "dev_appserver.py", then I got the above stacktrace. Django syncdb在这个设置下运行正常,django能够为我创建表。但是,当我尝试通过“dev_appserver.py”运行时,我得到了上面的堆栈跟踪。
I am able to access the cloudSQL in dev environment. 我可以在开发环境中访问cloudSQL。
This should work as mentioned here . 这应该像这里提到的那样工作。 I don't there is anything wrong with this code snippet.
我没有这个代码片段有什么问题。
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-project-id:your-instance-name',
'NAME': 'django_test',
'USER': 'root',
}
}
elif os.getenv('SETTINGS_MODE') == 'prod':
# Running in development, but want to access the Google Cloud SQL instance
# in production.
DATABASES = {
'default': {
'ENGINE': 'google.appengine.ext.django.backends.rdbms',
'INSTANCE': 'your-project-id:your-instance-name',
'NAME': 'django_test',
'USER': 'root',
}
}
else:
# Running in development, so use a local MySQL database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_test',
'USER': 'root',
'PASSWORD': 'root',
}
}
I have also been using Google App Engine with cloudsql in django and here are the settings that I have been using for deployment and local development and it works just fine !! 我也一直在django中使用带有cloudsql的Google App Engine,这里是我一直用于部署和本地开发的设置,它工作得很好!!
Settings for deployment in GAE 在GAE中部署的设置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/instance:appid',
'NAME': 'name_of_database',
'USER': 'mysql_user',
}
}
Settings for local development with App engine sdk 使用App引擎sdk进行本地开发的设置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'name_of_database',
'USER': 'mysql_user',
'PASSWORD': 'pwd',
'HOST': 'ip_address_of_cloudsql_instance', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.