summaryrefslogtreecommitdiff
path: root/docs/narr/templates.rst
blob: 0650480affb39646a74882d0807686de8bcb1e91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
.. _templates_chapter:

Templates
=========

A :term:`template` is a file on disk which can be used to render
dynamic data provided by a :term:`view`.  :mod:`pyramid` offers a
number of ways to perform templating tasks out of the box, and
provides add-on templating support through a set of bindings packages.

Out of the box, :mod:`pyramid` provides templating via the
:term:`Chameleon` templating library.  :term:`Chameleon` provides
support for two different types of templates: :term:`ZPT` templates
and text templates.

Before discussing how built-in templates are used in
detail, we'll discuss two ways to render templates within
:mod:`pyramid` in general: directly, and via renderer
configuration.

.. index::
   single: templates used directly
   single: Mako

.. _templates_used_directly:

Templates Used Directly
-----------------------

The most straightforward way to use a template within
:mod:`pyramid` is to cause it to be rendered directly within a
:term:`view callable`.  You may use whatever API is supplied by a
given templating engine to do so.

:mod:`pyramid` provides various APIs that allow you to render
templates directly from within a view callable.  For example, if there
is a :term:`Chameleon` ZPT template named ``foo.pt`` in a directory in
your application named ``templates``, you can render the template from
within the body of a view callable like so:

.. code-block:: python
   :linenos:

   from pyramid.renderers import render_to_response

   def sample_view(request):
       return render_to_response('templates/foo.pt', 
                                 {'foo':1, 'bar':2}, 
                                 request=request)

.. warning:: Earlier iterations of this documentation
   (pre-version-1.3) encouraged the application developer to use
   ZPT-specific APIs such as
   :func:`pyramid.chameleon_zpt.render_template_to_response` and
   :func:`pyramid.chameleon_zpt.render_template` to render templates
   directly.  This style of rendering still works, but at least for
   purposes of this documentation, those functions are deprecated.
   Application developers are encouraged instead to use the functions
   available in the :mod:`pyramid.renderers` module to perform
   rendering tasks.  This set of functions works to render templates
   for all renderer extensions registered with :mod:`pyramid`.

The ``sample_view`` :term:`view callable` above returns a
:term:`response` object which contains the body of the
``templates/foo.pt`` template.  In this case, the ``templates``
directory should live in the same directory as the module containing
the ``sample_view`` function.  The template author will have the names
``foo`` and ``bar`` available as top-level names for replacement or
comparison purposes.

In the example above, the path ``templates/foo.pt`` is relative to the
directory in which the file which defines the view configuration
lives.  In this case, this is the directory containing the file that
defines the ``sample_view`` function.  Although a renderer path is
usually just a simple relative pathname, a path named as a renderer
can be absolute, starting with a slash on UNIX or a drive letter
prefix on Windows.

The path can alternately be a :term:`resource specification` in the
form ``some.dotted.package_name:relative/path``, making it possible to
address template resources which live in another package.  For
example:

.. code-block:: python
   :linenos:

   from pyramid.renderers import render_to_response

   def sample_view(request):
       return render_to_response('mypackage:templates/foo.pt',
                                 {'foo':1, 'bar':2},
                                 request=request)

A resource specification points at a file within a Python *package*.
In this case, it points at a file named ``foo.pt`` within the
``templates`` directory of the ``mypackage`` package.  Using a
resource specification instead of a relative template name is usually
a good idea, because calls to ``render_to_response`` using resource
specifications will continue to work properly if you move the code
containing them around.

In the examples above we pass in a keyword argument named ``request``
representing the current :mod:`pyramid` request. Passing a request
keyword argument will cause the ``render_to_response`` function to
supply the renderer with more correct system values (see
:ref:`renderer_system_values`), because most of the information
required to compose proper system values is present in the request.
If you care about the correct system values being provided to the
renderer being called (in particular, if your template relies on the
name ``request`` or ``context``, or if you've configured special
:term:`renderer globals` make sure to pass ``request`` as a keyword
argument in every call to to a ``pyramid.renderers.render_*``
function.

Every view must return a :term:`response` object (except for views
which use a :term:`renderer` named via view configuration, which we'll
see shortly).  The :func:`pyramid.renderers.render_to_response`
function is a shortcut function that actually returns a response
object.

Obviously not all APIs you might call to get respnonse data will
return a response object.  If you call a "response-ignorant" API that
returns information you'd like to use as a response (such as when you
render a template to a string), you must construct your own response
object as necessary with the string as the body.  For example, the
:func:`pyramid.renderers.render` API returns a string.  We can
manufacture a :term:`response` object directly, and use that string as
the body of the response:

.. code-block:: python
   :linenos:

   from pyramid.renderers import render
   from webob import Response

   def sample_view(request):
       result = render('mypackage:templates/foo.pt', 
                       {'foo':1, 'bar':2}, 
                       request=request)
       response = Response(result)
       return response

Because :term:`view callable` functions are typically the only code in
:mod:`pyramid` that need to know anything about templates, and
because view functions are very simple Python, you can use whatever
templating system you're most comfortable with within
:mod:`pyramid`.  Install the templating system, import its API
functions into your views module, use those APIs to generate a string,
then return that string as the body of a :term:`WebOb`
:term:`Response` object.

For example, here's an example of using raw `Mako
<http://www.makotemplates.org/>`_ from within a :mod:`pyramid`
:term:`view`:

.. ignore-next-block
.. code-block:: python
   :linenos:

   from mako.template import Template
   from webob import Response

   def make_view(request):
       template = Template(filename='/templates/template.mak')
       result = template.render(name=request.params['name'])
       response = Response(result)
       return response

You probably wouldn't use this particular snippet in a project,
because it's easier to use the Mako renderer bindings which already
exist for :mod:`pyramid` named ``repoze.bfg.mako`` (available from
`PyPI <http://pypi.python.org/pypi/repoze.bfg.mako>`_).  But if your
favorite templating system is not supported as a renderer extension
for :mod:`pyramid`, you can create your own simple combination as
shown above.

.. note::

   If you use third-party templating languages without cooperating
   :mod:`pyramid` bindings directly within view callables, the
   auto-template-reload strategy explained in
   :ref:`reload_templates_section` will not be available, nor will the
   template resource overriding capability explained in
   :ref:`overriding_resources_section` be available, nor will it be
   possible to use any template using that language as a
   :term:`renderer`.  However, it's reasonably easy to write custom
   templating system binding packages for use under :mod:`pyramid` so
   that templates written in the language can be used as renderers.
   See :ref:`adding_and_overriding_renderers` for instructions on how
   to create your own template renderer and
   :ref:`available_template_system_bindings` for example packages.

If you need more control over the status code and content-type, or
other response attributes from views that use direct templating, you
may set attributes on the response that influence these values.

Here's an example of changing the content-type and status of the
response object returned by
:func:`pyramid.renderers.render_to_response`:

.. code-block:: python
   :linenos:

   from pyramid.renderers.render_to_response

   def sample_view(request):
       response = render_to_response('templates/foo.pt',
                                     {'foo':1, 'bar':2},
                                     request=request)
       response.content_type = 'text/plain'
       response.status_int = 204
       return response

Here's an example of manufacturing a response object using the result
of :func:`pyramid.renderers.render` (a string):

.. code-block:: python
   :linenos:

   from pyramid.renderers import render
   from webob import Response
   def sample_view(request):
       result = render('mypackage:templates/foo.pt',
                       {'foo':1, 'bar':2}, 
                       request=request)
       response = Response(result)
       response.content_type = 'text/plain'
       return response

.. index::
   single: templates used as renderers
   single: template renderers
   single: renderer (template)


.. _renderer_system_values:

System Values Used During Rendering
-----------------------------------

When a template is rendered using
:func:`pyramid.renderers.render_to_response` or
:func:`pyramid.renderers.render`, the renderer representing the
template will be provided with a number of *system* values.  These
values are provided in a dictionary to the renderer and include:

``context``
  The current :mod:`pyramid` context if ``request`` was provided as
  a keyword argument or ``None``.

``request``
  The request provided as a keyword argument.

``renderer_name``
  The renderer name used to perform the rendering,
  e.g. ``mypackage:templates/foo.pt``.

You can define more values which will be passed to every template
executed as a result of rendering by defining :term:`renderer
globals`.

What any particular renderer does with them is up to the renderer
itself, but most renderers, including al Chameleon renderers, make
these names available as top-level template variables.

.. _templates_used_as_renderers:

Templates Used as Renderers via Configuration
---------------------------------------------

Instead of using the :func:`pyramid.renderers.render_to_response`
API within the body of a view function directly to render a specific
template to a response, you may associate a template written in a
supported templating language with a view indirectly by specifying it
as a :term:`renderer` in *view configuration*.

To use a renderer via view configuration, specify a template
:term:`resource specification` as the ``renderer`` argument or
attribute to the :term:`view configuration` of a :term:`view
callable`.  Then return a *dictionary* from that view callable.  The
dictionary items returned by the view callable will be made available
to the renderer template as top-level names.

The association of a template as a renderer for a :term:`view
configuration` makes it possible to replace code within a :term:`view
callable` that handles the rendering of a template.

Here's an example of using a :class:`pyramid.view.bfg_view`
decorator to specify a :term:`view configuration` that names a
template renderer:

.. code-block:: python
   :linenos:

   from pyramid.view import bfg_view

   @bfg_view(renderer='templates/foo.pt')
   def my_view(request):
       return {'foo':1, 'bar':2}

.. note:: It is not necessary to supply the ``request`` value as a key
   in the dictionary result returned from a renderer-configured view
   callable in order to ensure that the "most correct" system values
   are supplied to the renderer as it is when you use
   :func:`pyramid.renderers.render` or
   :func:`pyramid.renderers.render_to_response`.  This is handled
   automatically.

Similar renderer configuration can be done imperatively and via
:term:`ZCML`.  See :ref:`views_which_use_a_renderer`.  See also
:ref:`built_in_renderers`.

The ``renderer`` argument to the ``@bfg_view`` configuration decorator
shown above is the template *path*.  In the example above, the path
``templates/foo.pt`` is *relative*.  Relative to what, you ask?
Relative to the directory in which the file which defines the view
configuration lives.  In this case, this is the directory containing
the file that defines the ``my_view`` function.

Although a renderer path is usually just a simple relative pathname, a
path named as a renderer can be absolute, starting with a slash on
UNIX or a drive letter prefix on Windows.  The path can alternately be
a :term:`resource specification` in the form
``some.dotted.package_name:relative/path``, making it possible to
address template resources which live in another package.

Not just any template from any arbitrary templating system may be used
as a renderer.  Bindings must exist specifically for :mod:`pyramid`
to use a templating language template as a renderer.  Currently,
:mod:`pyramid` has built-in support for two Chameleon templating
languages: ZPT and text.  See :ref:`built_in_renderers` for a
discussion of their details.  :mod:`pyramid` also supports the use
of :term:`Jinja2` templates as renderers.  See
:ref:`available_template_system_bindings`.

.. sidebar:: Why Use A Renderer via View Configuration

   Using a renderer in view configuration is usually a better way to
   render templates than using any rendering API directly from within
   a :term:`view callable` because it makes the view callable more
   unit-testable.  Views which use templating or rendering APIs
   directly must return a :term:`Response` object.  Making testing
   assertions about response objects is typically an indirect process,
   because it means that your test code often needs to somehow parse
   information out of the response body (often HTML).  View callables
   which are configured with renderers externally via view
   configuration typically return a dictionary, and making assertions
   about the information is almost always more direct than needing to
   parse HTML.  Specifying a renderer from within :term:`ZCML` (as
   opposed to imperatively or via a ``bfg_view`` decorator, or using a
   template directly from within a view callable) also makes it
   possible for someone to modify the template used to render a view
   without needing to fork your code to do so.  See
   :ref:`extending_chapter` for more information.

By default, views rendered via a template renderer return a
:term:`Response` object which has a *status code* of ``200 OK`` and a
*content-type* of ``text/html``.  To vary attributes of the response
of a view that uses a renderer, such as the content-type, headers, or
status attributes, you must set attributes on the *request* object
within the view before returning the dictionary.  See
:ref:`response_request_attrs` for more information.

The same set of system values are provided to templates rendered via a
rendere view configuration as those provided to templates rendered
imperatively.  See :ref:`renderer_system_values`.


.. index::
   single: Chameleon ZPT templates
   single: ZPT templates (Chameleon)

.. _chameleon_zpt_templates:

:term:`Chameleon` ZPT Templates
-------------------------------

Like :term:`Zope`, :mod:`pyramid` uses :term:`ZPT` (Zope Page
Templates) as its default templating language.  However,
:mod:`pyramid` uses a different implementation of the :term:`ZPT`
specification than Zope does: the :term:`Chameleon` templating
engine. The Chameleon engine complies largely with the `Zope Page
Template <http://wiki.zope.org/ZPT/FrontPage>`_ template
specification.  However, it is significantly faster.

The language definition documentation for Chameleon ZPT-style
templates is available from `the Chameleon website
<http://chameleon.repoze.org/>`_.

.. warning:: 

   :term:`Chameleon` only works on :term:`CPython` platforms and
   :term:`Google App Engine`.  On :term:`Jython` and other non-CPython
   platforms, you should use ``repoze.bfg.jinja2`` instead.  See
   :ref:`available_template_system_bindings`.

Given that there is a :term:`Chameleon` ZPT template named ``foo.pt``
in a directory in your application named ``templates``, you can render
the template as a :term:`renderer` like so:

.. code-block:: python
   :linenos:

   from pyramid.view import bfg_view

   @bfg_view(renderer='templates/foo.pt')
   def my_view(request):
       return {'foo':1, 'bar':2}

See also :ref:`built_in_renderers` for more general information about
renderers, including Chameleon ZPT renderers.

.. index::
   single: sample template

A Sample ZPT Template
~~~~~~~~~~~~~~~~~~~~~

Here's what a simple :term:`Chameleon` ZPT template used under
:mod:`pyramid` might look like:

.. code-block:: xml
   :linenos:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:tal="http://xml.zope.org/namespaces/tal">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>${project} Application</title>
    </head>
      <body>
         <h1 class="title">Welcome to <code>${project}</code>, an
	  application generated by the <a
	  href="http://pylonshq.com/pyramid">pyramid</a> web
	  application framework.</h1>
      </body>
    </html>

Note the use of :term:`Genshi` -style ``${replacements}`` above.  This
is one of the ways that :term:`Chameleon` ZPT differs from standard
ZPT.  The above template expects to find a ``project`` key in the set
of keywords passed in to it via :func:`pyramid.renderers.render` or
:func:`pyramid.renderers.render_to_response`. Typical ZPT
attribute-based syntax (e.g. ``tal:content`` and ``tal:replace``) also
works in these templates.

.. index::
   single: ZPT macros
   single: Chameleon ZPT macros

Using ZPT Macros in :mod:`pyramid`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When a :term:`renderer` is used to render a template,
:mod:`pyramid` makes at least two top-level names available to the
template by default: ``context`` and ``request``.  One of the common
needs in ZPT-based templates is to use one template's "macros" from within
a different template.  In Zope, this is typically handled by
retrieving the template from the ``context``.  But having a hold of
the context in :mod:`pyramid` is not helpful: templates cannot
usually be retrieved from models.  To use macros in :mod:`pyramid`,
you need to make the macro template itself available to the rendered
template by passing the template in which the macro is defined (or even
the macro itself) *into* the rendered template.  To make a macro
available to the rendered template, you can retrieve a different
template using the :func:`pyramid.renderers.get_renderer` API,
and pass it in to the template being rendered.  For example, using a
:term:`view configuration` via a :class:`pyramid.view.bfg_view`
decorator that uses a :term:`renderer`:

.. code-block:: python
   :linenos:

   from pyramid.renderers import get_renderer
   from pyramid.view import bfg_view

   @bfg_view(renderer='templates/mytemplate.pt')
   def my_view(request):
       main = get_renderer('templates/master.pt').implementation()
       return {'main':main}

Where ``templates/master.pt`` might look like so:

.. code-block:: xml
   :linenos:

    <html xmlns="http://www.w3.org/1999/xhtml" 
          xmlns:tal="http://xml.zope.org/namespaces/tal"
          xmlns:metal="http://xml.zope.org/namespaces/metal">
      <span metal:define-macro="hello">
        <h1>
          Hello <span metal:define-slot="name">Fred</span>!
        </h1>
      </span>
    </html>

And ``templates/mytemplate.pt`` might look like so:

.. code-block:: xml
   :linenos:

    <html xmlns="http://www.w3.org/1999/xhtml" 
          xmlns:tal="http://xml.zope.org/namespaces/tal"
          xmlns:metal="http://xml.zope.org/namespaces/metal">
      <span metal:use-macro="main.macros['hello']">
        <span metal:fill-slot="name">Chris</span>
      </span>
    </html>

.. index::
   single: Chameleon text templates

.. _chameleon_text_templates:

Templating with :term:`Chameleon` Text Templates
------------------------------------------------

:mod:`pyramid` also allows for the use of templates which are
composed entirely of non-XML text via :term:`Chameleon`.  To do so,
you can create templates that are entirely composed of text except for
``${name}`` -style substitution points.

Here's an example usage of a Chameleon text template.  Create a file
on disk named ``mytemplate.txt`` in your project's ``templates``
directory with the following contents::

   Hello, ${name}!

Then in your project's ``views.py`` module, you can create a view
which renders this template:

.. code-block:: python
   :linenos:

   from pyramid.view import bfg_view

   @bfg_view(renderer='templates/mytemplate.txt')
   def my_view(request):
       return {'name':'world'}

When the template is rendered, it will show:

.. code-block:: text

   Hello, world!

If you'd rather use templates directly within a view callable (without
the indirection of using a renderer), see :ref:`chameleon_text_module`
for the API description.

See also :ref:`built_in_renderers` for more general information about
renderers, including Chameleon text renderers.

.. index::
   single: template renderer side effects

Side Effects of Rendering a Chameleon Template
----------------------------------------------

When a Chameleon template is rendered from a file, the templating
engine writes a file in the same directory as the template file itself
as a kind of cache, in order to do less work the next time the
template needs to be read from disk. If you see "strange" ``.py``
files showing up in your ``templates`` directory (or otherwise
directly "next" to your templates), it is due to this feature.

If you're using a version control system such as Subversion, you
should cause it to ignore these files.  Here's the contents of the
author's ``svn propedit svn:ignore .`` in each of my ``templates``
directories.

.. code-block:: bash
   :linenos:

   *.pt.py
   *.txt.py

Note that I always name my Chameleon ZPT template files with a ``.pt``
extension and my Chameleon text template files with a ``.txt``
extension so that these ``svn:ignore`` patterns work.

.. index::
   single: automatic reloading of templates
   single: template automatic reload

.. _reload_templates_section:

Automatically Reloading Templates
---------------------------------

It's often convenient to see changes you make to a template file
appear immediately without needing to restart the application process.
:mod:`pyramid` allows you to configure your application development
environment so that a change to a template will be automatically
detected, and the template will be reloaded on the next rendering.

.. warning:: auto-template-reload behavior is not recommended for
             production sites as it slows rendering slightly; it's
             usually only desirable during development.

In order to turn on automatic reloading of templates, you can use an
environment variable setting or a configuration file setting.

To use an environment variable, start your application under a shell
using the ``BFG_RELOAD_TEMPLATES`` operating system environment
variable set to ``1``, For example::

  $ BFG_RELOAD_TEMPLATES=1 bin/paster serve myproject.ini

To use a setting in the application ``.ini`` file for the same
purpose, set the ``reload_templates`` key to ``true`` within the
application's configuration section, e.g.::

  [app:main]
  use = egg:MyProject#app
  reload_templates = true

.. _debug_templates_section:

Nicer Exceptions in Templates
-----------------------------

The exceptions raised by Chameleon templates when a rendering fails
are sometimes less than helpful.  :mod:`pyramid` allows you to
configure your application development environment so that exceptions
generated by Chameleon during template compilation and execution will
contain nicer debugging information.

.. warning:: template-debugging behavior is not recommended for
             production sites as it slows renderings; it's usually
             only desirable during development.

In order to turn on template exception debugging, you can use an
environment variable setting or a configuration file setting.

To use an environment variable, start your application under a shell
using the ``BFG_DEBUG_TEMPLATES`` operating system environment
variable set to ``1``, For example::

  $ BFG_DEBUG_TEMPLATES=1 bin/paster serve myproject.ini

To use a setting in the application ``.ini`` file for the same
purpose, set the ``debug_templates`` key to ``true`` within the
application's configuration section, e.g.::

  [app:main]
  use = egg:MyProject#app
  debug_templates = true

With template debugging off, a :exc:`NameError` exception resulting
from rendering a template with an undefined variable
(e.g. ``${wrong}``) might end like this::

  File "...", in __getitem__
    raise NameError(key)
  NameError: wrong

Note that the exception has no information about which template was
being rendered when the error occured.  But with template debugging
on, an exception resulting from the same problem might end like so::

    RuntimeError: Caught exception rendering template.
     - Expression: ``wrong``
     - Filename:   /home/fred/env/proj/proj/templates/mytemplate.pt
     - Arguments:  renderer_name: proj:templates/mytemplate.pt
                   template: <PageTemplateFile - at 0x1d2ecf0>
                   xincludes: <XIncludes - at 0x1d3a130>
                   request: <Request - at 0x1d2ecd0>
                   project: proj
                   macros: <Macros - at 0x1d3aed0>
                   context: <MyModel None at 0x1d39130>
                   view: <function my_view at 0x1d23570>

    NameError: wrong

The latter tells you which template the error occurred in, as well as
displaying the arguments passed to the template itself.

.. note::

   Turning on ``debug_templates`` has the same effect as using the
   Chameleon environment variable ``CHAMELEON_DEBUG``.  See `Chameleon
   Environment Variables
   <http://chameleon.repoze.org/docs/latest/config.html#environment-variables>`_
   for more information.

.. index::
   single: template internationalization
   single: internationalization (of templates)

:term:`Chameleon` Template Internationalization
-----------------------------------------------

See :ref:`chameleon_translation_strings` for information about
supporting internationalized units of text within :term:`Chameleon`
templates.

.. index::
   single: template system bindings
   single: Jinja2

.. _available_template_system_bindings:

Available Add-On Template System Bindings
-----------------------------------------

Jinja2 template bindings are available for :mod:`pyramid` in the
``repoze.bfg.jinja2`` package.  It lives in the Repoze Subversion
repository at `http://svn.repoze.org/repoze.bfg.jinja2
<http://svn.repoze.org/repoze.bfg.jinja2>`_; it is also available from
:term:`PyPI`.