Google App Engine:django.template を使う。

App Engine Python 環境には、Django 0.9.6 が付属しています。

django.template をインポートするだけで、利用できるかと思いましたが、そうではありませんでした。

色々試してみましたが、django.conf をインポートして、設定を書き込んだところ、うまくいきました。

なぜだかわかりませんが、とりあえずメモしておきます。

import django.conf
try:
  django.conf.settings.configure(
    DEBUG=False,
    TEMPLATE_DEBUG=False,
  )
except (EnvironmentError, RuntimeError):
  pass

import django.template

t = django.template.Template("This sentence is written by {{ name }} .")
c = django.template.Context({"name": "Netarrows"})
u = t.render(c)
print u