我有一个使用Django 1.2的Python 2.7 GAE应用程序。一切都很顺利。
我正在尝试使用remote_api_shell.py
,但是当我导入models.py
时,我收到此错误:
$ PYTHONPATH=.; remote_api_shell.py APP
App Engine remote_api shell
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
The db, users, urlfetch, and memcache modules are imported.
s~APP> import models
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/.../models.py", line 8, in <module>
from django.core.validators import email_re
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_0_96/django/core/validators.py", line 13, in <module>
from django.utils.translation import gettext, gettext_lazy, ngettext
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_0_96/django/utils/translation/__init__.py", line 3, in <module>
if settings.USE_I18N:
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_0_96/django/conf/__init__.py", line 28, in __getattr__
self._import_settings()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django_0_96/django/conf/__init__.py", line 53, in _import_settings
raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE
EnvironmentError: Environment variable DJANGO_SETTINGS_MODULE is undefined.
我不知道为什么在这里使用Django 0.96。特别是因为我认为Python 2.7仅支持Django 1.2。以下是我app.yaml
的相关部分:
application: APP
version: prod
runtime: python27
api_version: 1
threadsafe: true
[...]
libraries:
- name: django
version: "1.2"
如果我注释掉from django.core.validators import email_re
行,则导入成功。
我知道我做错了什么或者这是一个GAE错误吗?
答案 0 :(得分:3)
我遇到了同样的问题,一旦打开远程API会话,我就通过运行这两行解决了这个问题:
from google.appengine.dist import use_library
use_library('django', '1.3')
虽然,显然,这是一个黑客。明星这个问题鼓励应用引擎团队解决它:
https://code.google.com/p/googleappengine/issues/detail?id=8716
答案 1 :(得分:1)
尝试输入:
import django
django.VERSION
检查django版本!我猜你正在运行的python控制台有旧版本的django!
答案 2 :(得分:0)
仅供参考,这不再有效,因为
use_library('django', '1.5')
现在抛出此错误:
ValueError: 1.5 is not a supported version for django; supported versions are ['0.96', '1.0', '1.1', '1.2', '1.3']
希望这是一个暂时的问题,但我的解决方案是删除(重命名):
C:\Program Files (x86)\Google\google_appengine\lib\django-0.96
到其他东西,然后django的正确版本加载没有任何其他问题。