I'm working on a Google App Engine project and have been running into issues trying to set up the basic Django Admin Site with MySQL. I have searched around about this question, but all I see people posting about deals with running apps locally. In my situation, I'm getting an error when running the app in Google App Engine.
我正在开发一个谷歌应用程序引擎项目,并且一直在尝试用MySQL建立基本的Django管理站点。我已经搜索了这个问题,但是我看到的所有人都是在本地运行应用程序。在我的情况下,在谷歌应用程序引擎中运行应用程序时,我遇到了一个错误。
To be more specific about the issue, I get the following error in the logs for my application:
为了更具体地讨论这个问题,我在我的应用程序日志中有以下错误:
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
This makes it seem like MySQL isn't even installed, which doesn't really make sense. It should be accessible by default in GAE. Is there another issue that I'm not seeing? This is confusing for me because it doesn't even give me a specific line to look at, or any kind of lead.
这使得MySQL似乎还没有安装,这是没有意义的。在GAE中默认是可访问的。还有其他问题吗?这让我很困惑,因为它甚至没有给我一个特定的线去看,或者任何一种线索。
I've looked through the GAE documentation for Django and CloudSQL but nothing I had seemed out of place. I also took a look at the example Django app and all of my content didn't seem to conflict with what they had there.
我已经查看了Django和CloudSQL的GAE文档,但我没有发现什么地方不合适。我还看了Django应用程序的例子,我的所有内容似乎与他们在那里的内容没有冲突。
The full log is here:
完整的日志在这里:
E 21:59:53.098 Internal Server Error: /admin/
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/core/handlers/base.py", line 87, in get_response
response = middleware_method(request)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/contrib/sessions/middleware.py", line 10, in process_request
engine = import_module(settings.SESSION_ENGINE)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/contrib/sessions/backends/db.py", line 3, in <module>
from django.db import IntegrityError, transaction, router
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/db/utils.py", line 24, in load_backend
return import_module('.base', backend_name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/db/backends/mysql/base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
E 21:59:53.227 Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 267, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/core/handlers/base.py", line 177, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/core/handlers/base.py", line 219, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/views/debug.py", line 66, in technical_500_response
html = reporter.get_traceback_html()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/views/debug.py", line 287, in get_traceback_html
return t.render(c)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/template/base.py", line 140, in render
return self._render(context)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/template/base.py", line 134, in _render
return self.nodelist.render(context)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/template/base.py", line 823, in render
bit = self.render_node(node, context)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/template/debug.py", line 74, in render_node
return node.render(context)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/template/debug.py", line 84, in render
output = self.filter_expression.resolve(context)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/template/base.py", line 599, in resolve
new_obj = func(obj, *arg_vals)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/template/defaultfilters.py", line 718, in date
return format(value, arg)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/dateformat.py", line 310, in format
return df.format(format_string)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/dateformat.py", line 33, in format
pieces.append(force_unicode(getattr(self, piece)()))
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/dateformat.py", line 214, in r
return self.format('D, j M Y H:i:s O')
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/dateformat.py", line 33, in format
pieces.append(force_unicode(getattr(self, piece)()))
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/encoding.py", line 71, in force_unicode
s = unicode(s)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/functional.py", line 121, in __unicode_cast
return func(*self.__args, **self.__kw)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/translation/__init__.py", line 86, in ugettext
return _trans.ugettext(message)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/translation/trans_real.py", line 278, in ugettext
return do_translate(message, 'ugettext')
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/translation/trans_real.py", line 268, in do_translate
_default = translation(settings.LANGUAGE_CODE)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/translation/trans_real.py", line 183, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/translation/trans_real.py", line 160, in _fetch
app = import_module(appname)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/contrib/admin/__init__.py", line 3, in <module>
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/contrib/admin/helpers.py", line 2, in <module>
from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/contrib/admin/util.py", line 1, in <module>
from django.db import models
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/db/utils.py", line 24, in load_backend
return import_module('.base', backend_name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.4/django/db/backends/mysql/base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
Relevant portions of settings.py:
settings.py相关部分:
import os
DEBUG = True
TEMPLATE_DEBUG = DEBUG
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'userinformation',
'USER': 'root',
'HOST': '/cloudsql/eloquent-ratio-109701:api-instance',
}
}
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
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',
],
},
},
]
ROOT_URLCONF = 'Chimera.urls'
WSGI_APPLICATION = 'Chimera.wsgi.app'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'API',
)
If you have any idea what could be going on, I'd really appreciate pointing me in the right direction. I can post any more significant source files here as well.
如果你知道接下来会发生什么,我会非常感谢你给我指明方向。我还可以在这里发布更重要的源文件。
1 个解决方案
#1
0
Did you specify the MySQLdb
library in your app.yaml
config?
您在app.yaml配置中指定了MySQLdb库吗?
GAE has some specific support for using Django, I'd strongly suggest going through the Django Support documentation and the Django App example.
GAE对使用Django有一些特定的支持,我强烈建议通过Django支持文档和Django应用程序示例。
Update - an experiment:
更新——一个实验:
I just added this to the libraries
section of my (non-Django) app's .yaml
file:
我刚刚把这个添加到我的(非django)应用程序的。yaml文件的库中:
- name: MySQLdb
version: "latest"
And added this to one of my handlers:
并把它添加到我的一个处理器:
import MySQLdb
print MySQLdb.apilevel
After deploying the changes on GAE and triggering the handler I got this log entry (same 2.0
content as on my dev server):
在部署了GAE上的更改并触发处理程序后,我得到了这个日志条目(与我的dev服务器相同的2.0内容):
Which IMHO proves MySQLdb
is available in GAE and can be imported with no issues.
IMHO证明了MySQLdb在GAE中是可用的,并且可以在没有问题的情况下导入。
#1
0
Did you specify the MySQLdb
library in your app.yaml
config?
您在app.yaml配置中指定了MySQLdb库吗?
GAE has some specific support for using Django, I'd strongly suggest going through the Django Support documentation and the Django App example.
GAE对使用Django有一些特定的支持,我强烈建议通过Django支持文档和Django应用程序示例。
Update - an experiment:
更新——一个实验:
I just added this to the libraries
section of my (non-Django) app's .yaml
file:
我刚刚把这个添加到我的(非django)应用程序的。yaml文件的库中:
- name: MySQLdb
version: "latest"
And added this to one of my handlers:
并把它添加到我的一个处理器:
import MySQLdb
print MySQLdb.apilevel
After deploying the changes on GAE and triggering the handler I got this log entry (same 2.0
content as on my dev server):
在部署了GAE上的更改并触发处理程序后,我得到了这个日志条目(与我的dev服务器相同的2.0内容):
Which IMHO proves MySQLdb
is available in GAE and can be imported with no issues.
IMHO证明了MySQLdb在GAE中是可用的,并且可以在没有问题的情况下导入。