在 app-engine-patch 中导入 django 设置
我的 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?
谢谢!
I have a problem with Django settings.
My app runs with app-engine-patch.
I added a script that runs without django, and is reached directly via the app.yaml handlers.
I then get this error:
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.
I found this tip in 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'
But then I got this error:
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
I think it is a problem with app-engine-patch paths modification, how can I import settings_pre correctly?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改
为
DJANGO_SETTINGS_MODULE
的值是模块的名称(即,正如您在 Python 脚本的import
语句中编写的那样),而不是模块的路径模块。Change
to
The value of the
DJANGO_SETTINGS_MODULE
is the name of the module (ie, as you would write it in animport
statement in a Python script), not the path to the module.感谢另一个问题,我将 beinning 替换为:
This imports all the settings and my task can run withoutreference to Django
Thanks to another question, I replaced the beinning with:
This imports all the settings and my task can run without reference to Django