Search code examples
pythonpython-2.7bottle

Bottle multiple template variables


Is there any way to give the template multiple variables through bottle? i know that you can use template('mytemplate.tpl',var=var) and such, however, how can you use multiple variables?


Solution

  • As you can see in the signature, one can pass any number of variables to the template by using keyword arguments:

    template('mytemplate.tpl', name="Anne", address="4 Elm Street", 
                              dob=datetime.datetime(1977,12,2,1,2,3))
    

    or like this

    d = { "name": "Anne", "address": "4 Elm Street", "dob": datetime.datetime(1977,12,2,1,2,3) }
    template('mytemplate.tpl', **d)