将python / django app部署到gae

时间:2013-02-05 19:11:10

标签: python django google-app-engine

我在本地运行的Django教程中有“mysite / poll”应用,我正在尝试部署到GAE。我在wsgi.py和admin.py中定义了DJANGO_SETTINGS_MODULE

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

这是部署的回溯:

Traceback (most recent call last):
  File "/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py",      line 196, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
      File        "/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 255, in   _LoadHandler
    handler = __import__(path[0])
  File "/base/data/home/apps/s~ceemee11111/1.365096182895980177/admin.py", line 1, in <module>
from django.contrib import admin
  File "/python27_runtime/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 "/python27_runtime/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 "/python27_runtime/python27_lib/versions/third_party/django-          1.4/django/contrib/admin/util.py", line 1, in <module>
    from django.db import models
  File "/python27_runtime/python27_lib/versions/third_party/django-1.4/django/db/__init__.py", line 11, in <module>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  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.

为什么DJANGO_SETTINGS_MODULE仍未定义

由于 丹

2 个答案:

答案 0 :(得分:1)

请改为尝试:

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

答案 1 :(得分:1)

https://developers.google.com/appengine/docs/python/tools/libraries27#django

您也可以尝试添加

env_variables:
  DJANGO_SETTINGS_MODULE: 'myapp.settings'

在app.yaml