【发布时间】:2023-03-17 03:26:01
【问题描述】:
这是Google App Engine and Django support的后续问题:
本教程非常适合空项目,但是当我尝试将现有 Django 应用部署到 Google App Engine 时,它开始抛出错误:
Traceback (most recent call last):
File "/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 223, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/core/handlers/wsgi.py", line 219, in __call__
self.load_middleware()
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/core/handlers/base.py", line 39, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/utils/functional.py", line 184, in inner
self._setup()
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
还有第二个,这可能是相关的:
Traceback (most recent call last):
File "/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 223, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/core/handlers/wsgi.py", line 219, in __call__
self.load_middleware()
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/core/handlers/base.py", line 39, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/utils/functional.py", line 184, in inner
self._setup()
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'settings' (Is it on sys.path?): No module named settings
我已按照教程修改了我的 settings.py。该应用程序部署没有问题,并且同步数据库也可以正常工作;数据库和所有必需的表都已到位。
我在日志中显示的错误消息中找到了this reference,但其建议的修复没有帮助。
任何想法可能导致这种情况?
编辑:
为了缩短这个已经很长的问题,我删除了之前发布的wsgi.py 文件。我与这个问题无关。
编辑 2:
我想我做了一点小改进,GAE 现在抱怨:
ImportError: No module named properties
我认为我的 app.yaml 文件中可能缺少一个条目,但我不知道可能是哪个文件。我发现了一些关于缺少模块的参考资料,但没有一个反映此错误消息...
【问题讨论】:
-
尝试在
wsgi.py文件顶部添加项目路径,请参阅 here 如果添加路径不起作用,请发布您的wsgi.py -
嗯,看起来我使用了不同的目录结构。我只是忽略了外部目录(在您的示例中为
pms)并且只在内部目录中工作。我必须承认我没有比我的教程更进一步。对我来说,接下来的事情也是将我现有的项目转换为 GAE 项目。 -
结构是 AFAIK 创建新 Django 项目时获得的结构。我最终设法让整个事情正常进行(请参阅我的答案),但这绝对是一条非常崎岖的道路。 GAE 日志消息不一定指向实际问题这一事实无济于事。祝你好运!