Python 将变量传递到PyBattle中的多个模板
我们在controller.py中有一个函数:Python 将变量传递到PyBattle中的多个模板,python,bottle,Python,Bottle,我们在controller.py中有一个函数: @bottle.get("/") def start(): username = check_login() l = artifacts.get_entries(100) return bottle.template('streams_template', dict(myentries=l, username=username)) streams_template.tpl % include menu.t
@bottle.get("/")
def start():
username = check_login()
l = artifacts.get_entries(100)
return bottle.template('streams_template',
dict(myentries=l, username=username))
streams_template.tpl
% include menu.tpl
菜单.tpl
<a class="menu" href="/cart/{{username}}"><div class="menulist">Your Cart</div></a>
这将生成:name错误:未定义名称“username”
如何将{username}传递到menu.tpl?对不起。这很容易。只需要像这样在include中传递变量:%include菜单username=username