Google App Engine with local Django 1.1 gets Intermittent Failures

Posted by Jon Watte on Stack Overflow See other posts from Stack Overflow or by Jon Watte
Published on 2010-06-06T22:52:59Z Indexed on 2010/06/06 23:02 UTC
Read the original article Hit count: 261

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).

© Stack Overflow or respective owner

Related posts about python

Related posts about django