在app-engine-patch中导入django设置

时间:2010-08-26 21:10:22

标签: python django google-app-engine app-engine-patch

我的Django设置有问题。 我的应用程序使用app-engine-patch运行。 我添加了一个没有django运行的脚本,可以通过app.yaml处理程序直接访问。 然后我得到了这个错误:

File "/base/python_runtime/python_lib/versions/third_party/django-0.96/django/conf/__init__.py", line 53, in _import_settings
raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE
<type 'exceptions.EnvironmentError'>: Environment variable DJANGO_SETTINGS_MODULE is undefined.

我在google中找到了这个提示:

# Force Django to reload its settings.
from django.conf import settings
settings._target = None

# Must set this env var before importing any part of Django
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 

但后来我收到了这个错误:

raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
<type 'exceptions.EnvironmentError'>: Could not import settings 'settings.py' (Is it on sys.path? Does it have syntax errors?): No module named ragendja.settings_pre

我认为app-engine-patch路径修改存在问题,如何正确导入settings_pre?

谢谢!

2 个答案:

答案 0 :(得分:3)

更改

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

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

DJANGO_SETTINGS_MODULE的值是模块的名称(即,您将在Python脚本中的import语句中编写它),而不是模块的路径。

答案 1 :(得分:0)

感谢另一个问题,我将开头替换为:

from common.appenginepatch.aecmd import setup_env 
setup_env(manage_py_env=True)

这会导入所有设置,我的任务可以在不参考Django的情况下运行