我对 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.
我在谷歌找到了这个提示:
# 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?
谢谢!