Accessing Variables

As you already know, the template knows the variables by the names they were given as dictionary keys. So if the dictionary passed to the render function was this:

The following statements in the template can access these variables as shown here: {{ name }} / {{ age }}

The object passed to the template can be any Python object, and the template can access it using the same Python syntax. For example, you can access the dictionary or array elements. Assume the following render call:

person = {'name': 'John', 'age': 30} r = t.render({'person': person})

Then you can use the following syntax to access the dictionary elements in the template:

Was this article helpful?

0 0

Post a comment