Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将变量传递到PyBattle中的多个模板_Python_Bottle - Fatal编程技术网

Python 将变量传递到PyBattle中的多个模板

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

我们在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.tpl
菜单.tpl

<a class="menu" href="/cart/{{username}}"><div class="menulist">Your Cart</div></a>

这将生成:name错误:未定义名称“username”


如何将{username}传递到menu.tpl?

对不起。这很容易。只需要像这样在include中传递变量:%include菜单username=username