[英]Switching from bottle.template to mako
因為我需要在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)}}
我接受了presveva的回答,但我想補充一點,就是我能夠使用bottle中的函數。 我只需要從舊版本的bottle-0.10更新到bottle-0.12。
我這樣稱呼它:
%variable_name = py_package_name.python_file.function_name(input_variable)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.