因为我需要在tpl文件中定义一个函数,所以需要从bottle切换。
我的问题有两个:
这是现有的代码:
@bottle.route('/showDevice')
def device_view():
device_id = bottle.request.query.id
result = lib.crud_ops.find_by_id(collection, device_id)
return bottle.template('device_view.tpl', {'device':result})
我尝试添加一些内容:
myTemplate = Template(filename='device_view.tpl')
myTemplate.render(device=result)
但是Mako不知道我的“ device_view.tpl”文件在哪里,而且我不确定“设备”是否作为字典传递。
您可以定义要在模板中使用的函数,即使使用bottle的也可以SimpleTemplate
:
def func():
...
def device_view():
return bottle.template('device_view.tpl', {'device':result, 'func':func})
{{func(data)}}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句