This commit updates the examples to conform to Python 3 instead
of Python 2, as Python 3 is more acceptable these days.
To render it with some variables, just call the :meth:`render` method::
- print template.render(the='variables', go='here')
+ print(template.render(the='variables', go='here'))
Using a template loader rather than passing strings to :class:`Template`
or :meth:`Environment.from_string` has multiple advantages. Besides being
def is_prime(n):
if n == 2:
return True
- for i in xrange(2, int(math.ceil(math.sqrt(n))) + 1):
+ for i in range(2, int(math.ceil(math.sqrt(n))) + 1):
if n % i == 0:
return False
return True
iterate over containers like `dict`::
<dl>
- {% for key, value in my_dict.iteritems() %}
+ {% for key, value in my_dict.items() %}
<dt>{{ key|e }}</dt>
<dd>{{ value|e }}</dd>
{% endfor %}
/
Divide two numbers. The return value will be a floating point number.
``{{ 1 / 2 }}`` is ``{{ 0.5 }}``.
- (Just like ``from __future__ import division``.)
//
Divide two numbers and return the truncated integer result.