带有本地 Django 1.1 的 Google App Engine 出现间歇性故障

发布于 2024-09-04 21:20:27 字数 2026 浏览 7 评论 0原文

我正在使用 Google App Engine 的 Windows Launcher 开发环境。

我已经下载了 Django 1.1.2 源代码,并将“django”子目录解压缩到我的应用程序目录中(app.yaml 的同级)

在每个 .py 源文件的顶部,我执行以下操作:

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

在我的文件设置中.py(也位于应用程序目录的根目录中),我这样做:

DEBUG = True
TEMPLATE_DIRS = ('html')
INSTALLED_APPS = ('filters')

import os
os.environ["DJANGO_SETTINGS_MODULE"] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')
from django.template import loader

是的,这看起来有点像矫枉过正,不是吗?

我只使用 django.template。我没有明确使用 django 的任何其他部分。

但是,我间歇性地收到两个错误之一:

1)Django 抱怨 DJANGO_SETTINGS_MODULE 未定义。
2)Django抱怨common.html(我在其他模板中扩展的模板)不存在。

95% 的情况下,这些错误不会遇到,它们只是随机开始发生。一旦处于该状态,本地服务器似乎“楔入”,重新启动通常可以修复它。

是什么原因导致这种情况发生,我该怎么办?我怎样才能调试它?

这是错误的回溯:

Traceback (most recent call last):
  File "C:\code\kwbudget\edit_budget.py", line 34, in get
    self.response.out.write(t.render(template.Context(values)))
  File "C:\code\kwbudget\django\template\__init__.py", line 165, in render
    return self.nodelist.render(context)
  File "C:\code\kwbudget\django\template\__init__.py", line 784, in render
    bits.append(self.render_node(node, context))
  File "C:\code\kwbudget\django\template\__init__.py", line 797, in render_node
    return node.render(context)
  File "C:\code\kwbudget\django\template\loader_tags.py", line 71, in render
    compiled_parent = self.get_parent(context)
  File "C:\code\kwbudget\django\template\loader_tags.py", line 66, in get_parent
    raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
TemplateSyntaxError: Template u'common.html' cannot be extended, because it doesn't exist

并且 edit_budget.py 从我在顶部包含的行开始。

所有模板都位于我的根目录中名为“html”的目录中,并且存在“html/common.html”。我知道模板引擎找到它们,因为我从扩展 common.html 的“html/edit_budget.html”开始。
看起来设置模块似乎没有被应用(因为这就是将 html 添加到模板的搜索路径中的原因)。

I'm using the Windows Launcher development environment for Google App Engine.

I have downloaded Django 1.1.2 source, and un-tarrred the "django" subdirectory to live within my application directory (a peer of app.yaml)

At the top of each .py source file, I do this:

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

In my file settings.py (which lives at the root of the app directory, as well), I do this:

DEBUG = True
TEMPLATE_DIRS = ('html')
INSTALLED_APPS = ('filters')

import os
os.environ["DJANGO_SETTINGS_MODULE"] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')
from django.template import loader

Yes, this looks a bit like overkill, doesn't it?

I only use django.template. I don't explicitly use any other part of django.

However, intermittently I get one of two errors:

1) Django complains that DJANGO_SETTINGS_MODULE is not defined.
2) Django complains that common.html (a template I'm extending in other templates) doesn't exist.

95% of the time, these errors are not encountered, and they randomly just start happening. Once in that state, the local server seems "wedged" and re-booting it generally fixes it.

What's causing this to happen, and what can I do about it? How can I even debug it?

Here is the traceback from the error:

Traceback (most recent call last):
  File "C:\code\kwbudget\edit_budget.py", line 34, in get
    self.response.out.write(t.render(template.Context(values)))
  File "C:\code\kwbudget\django\template\__init__.py", line 165, in render
    return self.nodelist.render(context)
  File "C:\code\kwbudget\django\template\__init__.py", line 784, in render
    bits.append(self.render_node(node, context))
  File "C:\code\kwbudget\django\template\__init__.py", line 797, in render_node
    return node.render(context)
  File "C:\code\kwbudget\django\template\loader_tags.py", line 71, in render
    compiled_parent = self.get_parent(context)
  File "C:\code\kwbudget\django\template\loader_tags.py", line 66, in get_parent
    raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
TemplateSyntaxError: Template u'common.html' cannot be extended, because it doesn't exist

And edit_budget.py starts with exactly the lines that I included up top.

All templates live in a directory named "html" in my root directory, and "html/common.html" exists. I know the template engine finds them, because I start out with "html/edit_budget.html" which extends common.html.
It looks as if the settings module somehow isn't applied (because that's what adds html to the search path for templates).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谜兔 2024-09-11 21:20:27

首先,虽然 django 现在比以前更兼容应用程序引擎,但两个平台之间仍然存在一些主要的不兼容性,这意味着您不能将 django 的库存副本转储到您的应用程序引擎目录中并让它在应用程序引擎之外工作。盒子。事情会以奇怪的方式出错。

有许多项目旨在提高两个项目之间的兼容性,其中最突出的是 app-engine-patch。我强烈建议您阅读以下文章 http://code.google.com /appengine/articles/app-engine-patch.html 以及位于 code.google.com/appengine/articles/ django 标签下的其余文章。

至于你们中的一些特定问题,您可以在设置脚本中尝试此操作:

#setup django environment
from django.core.management import setup_environ
import settings
setup_envion(settings)

这是 django 在内部使用的用于在 manage.py 中设置环境的内容,并且是设置 django 与脚本一起使用的公认最佳实践(例如应用程序引擎)。

Firstly, although django is now a LOT more compatible with app engine than it once, some major incompatibilities still exist between the two platforms, meaning that you can't just dump a stock copy of django into your appengine directory and have it work out of the box. Things will error in strange ways.

There are a number of projects which aim to improve compatibility between the two projects, the most prominent is app-engine-patch. I highly suggest reading the following article http://code.google.com/appengine/articles/app-engine-patch.html and the rest of the articles located at code.google.com/appengine/articles/ under the django tab.

as for some of you're specific problems, you could try this within your setup script:

#setup django environment
from django.core.management import setup_environ
import settings
setup_envion(settings)

this is what django uses internally for setting up the environment within manage.py and is the accepted best practice for setting up django for use with scripts (like app engine).

二手情话 2024-09-11 21:20:27

我遇到了完全相同的问题,而且我无法解决它......尽管我注意到真正的 GAE 发生的情况比我在 Linux 工作站上运行的开发服务器发生的情况要少得多。

I'm having exactly the same issue, and I haven't been able to work around it... though I've noticed it happens a LOT less with the real GAE than it does with the development server I run on my Linux workstation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文