もっと手軽にdjangoのテンプレートを使いたい。
djangoのtemplateをもっと手軽に、具体的にはviewsとtemplate分けたりせずに使いたい。*1
要求
- webAPIの動作確認をするために、いちいち、ファイル分けたくない。
もっと手軽に利用したい。
code
以下のようにすると使えた。
import django.template as tmpl from django.conf import settings settings.configure() t = tmpl.Template("hey {{ name }}, {{ message }}") c = tmpl.Context({"name": "foo", "message": "what's up?"}) print t.render(c)
hey foo, what's up?
*1:jinja2とか違うtemplate engineつかえと言う話もある。