Jun 132011
 

http://docs.djangoproject.com/en/dev/ref/templates/api/

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]
Rating: 0.0/10 (0 votes cast)

Related Posts:

  One Response to “The Django template engine”

 Leave a Reply

(required)

(required)


6 + two =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>