Jun 132011
http://docs.djangoproject.com/en/dev/ref/templates/api/
- Documentation on the tags: https://docs.djangoproject.com/en/dev/ref/templates/builtins/
- Setup in standalone-mode (without Django): https://docs.djangoproject.com/en/dev/ref/templates/api/#configuring-the-template-system-in-standalone-mode
Using the template system, a two-step process:
- First, you compile the raw template code into a Template object.
- Then, you call the
render()method of the Template object with a given context.
Example for use in standalone-mode:
from django.conf import settings
settings.configure( DEBUG=True,
TEMPLATE_DEBUG=True,
TEMPLATE_DIRS=()
)
from django.template import Context, Template # for the template engine
t = Template("My name is {{ my_name }}.")
c = Context({"my_name": "Adrian"})
print t.render(c)
c = Context({"my_name": "Dolores"})
print t.render(c)
VN:F [1.9.22_1171]
[...] The Django template engine [...]