gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 01:42:25 33 4
gpt4 key购买 nike

我对 Django 设置有疑问。我的应用程序使用应用程序引擎补丁运行。我添加了一个无需 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?

谢谢!

最佳答案

改变

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

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

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

关于python - 在 app-engine-patch 中导入 django 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3579544/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com